@@ -120,3 +120,49 @@ func ExampleClient_GenerateSpeechFromText() {
120120
121121 // Output:
122122}
123+
124+ func ExampleClient_GetAudioTranslation () {
125+ azureOpenAIKey := os .Getenv ("AZURE_OPENAI_API_KEY" )
126+
127+ // Ex: "https://<your-azure-openai-host>.openai.azure.com"
128+ azureOpenAIEndpoint := os .Getenv ("AZURE_OPENAI_ENDPOINT" )
129+
130+ modelDeploymentID := os .Getenv ("AZURE_OPENAI_DEPLOYMENT_ID" )
131+
132+ if azureOpenAIKey == "" || azureOpenAIEndpoint == "" || modelDeploymentID == "" {
133+ fmt .Fprintf (os .Stderr , "Skipping example, environment variables missing\n " )
134+ return
135+ }
136+
137+ keyCredential := azcore .NewKeyCredential (azureOpenAIKey )
138+
139+ client , err := azopenai .NewClientWithKeyCredential (azureOpenAIEndpoint , keyCredential , nil )
140+
141+ if err != nil {
142+ // TODO: Update the following line with your application specific error handling logic
143+ log .Printf ("ERROR: %s" , err )
144+ return
145+ }
146+ mp3Bytes , err := os .ReadFile ("testdata/sampleaudio_hindi_myVoiceIsMyPassportVerifyMe.mp3" )
147+
148+ if err != nil {
149+ // TODO: Update the following line with your application specific error handling logic
150+ log .Printf ("ERROR: %s" , err )
151+ return
152+ }
153+
154+ resp , err := client .GetAudioTranslation (context .TODO (), azopenai.AudioTranslationOptions {
155+ File : mp3Bytes ,
156+ DeploymentName : & modelDeploymentID ,
157+ Prompt : to .Ptr ("Translate the following Hindi audio to English" ),
158+ }, nil )
159+
160+ if err != nil {
161+ // TODO: Update the following line with your application specific error handling logic
162+ log .Printf ("ERROR: %s" , err )
163+ return
164+ }
165+
166+ // Output:
167+ fmt .Fprintf (os .Stderr , "Transcribed json: %s\n " , * resp .Text )
168+ }
0 commit comments