@@ -8,18 +8,14 @@ import (
88 "fmt"
99 "io"
1010 "os"
11+ "path/filepath"
1112 "testing"
1213
13- "github.com/Azure/azure-sdk-for-go/sdk/internal/recording"
1414 "github.com/openai/openai-go/v3"
1515 "github.com/stretchr/testify/require"
1616)
1717
1818func TestClient_GetAudioTranscription (t * testing.T ) {
19- if recording .GetRecordMode () != recording .LiveMode {
20- t .Skip ("https://github.com/Azure/azure-sdk-for-go/issues/22869" )
21- }
22-
2319 client := newStainlessTestClientWithAzureURL (t , azureOpenAI .Whisper .Endpoint )
2420 model := azureOpenAI .Whisper .Model
2521
@@ -51,10 +47,6 @@ func TestClient_GetAudioTranscription(t *testing.T) {
5147}
5248
5349func TestClient_GetAudioTranslation (t * testing.T ) {
54- if recording .GetRecordMode () != recording .LiveMode {
55- t .Skip ("https://github.com/Azure/azure-sdk-for-go/issues/22869" )
56- }
57-
5850 client := newStainlessTestClientWithAzureURL (t , azureOpenAI .Whisper .Endpoint )
5951 model := azureOpenAI .Whisper .Model
6052
@@ -70,11 +62,22 @@ func TestClient_GetAudioTranslation(t *testing.T) {
7062 require .NotEmpty (t , resp .Text )
7163}
7264
73- func TestClient_GetAudioSpeech (t * testing.T ) {
74- if recording .GetRecordMode () != recording .LiveMode {
75- t .Skip ("https://github.com/Azure/azure-sdk-for-go/issues/22869" )
76- }
65+ // fakeFlacFile works around a problem with the Stainless client's use of .Name() on the
66+ // passed in file and how it causes our test recordings to not match if the filename or
67+ // path is randomized.
68+ type fakeFlacFile struct {
69+ inner io.Reader
70+ }
71+
72+ func (f * fakeFlacFile ) Read (p []byte ) (n int , err error ) {
73+ return f .inner .Read (p )
74+ }
75+
76+ func (f * fakeFlacFile ) Name () string {
77+ return "audio.flac"
78+ }
7779
80+ func TestClient_GetAudioSpeech (t * testing.T ) {
7881 var tempFile * os.File
7982
8083 // Generate some speech from text.
@@ -100,21 +103,25 @@ func TestClient_GetAudioSpeech(t *testing.T) {
100103 require .NotEmpty (t , audioBytes )
101104 require .Equal (t , "fLaC" , string (audioBytes [0 :4 ]))
102105
103- // write the FLAC to a temp file - the Stainless API uses the filename of the file
104- // when it sends the request.
105- tempFile , err = os . CreateTemp ( "" , "audio* .flac" )
106+ // For test recordings, make sure we write the FLAC to a temp file with a consistent base name - the
107+ // Stainless API uses the filename of the file when it sends the request
108+ flacPath := filepath . Join ( t . TempDir () , "audio.flac" )
106109 require .NoError (t , err )
107110
108- t . Cleanup ( func () {
109- err := tempFile . Close ( )
110- require . NoError ( t , err )
111- })
111+ writer , err := os . Create ( flacPath )
112+ require . NoError ( t , err )
113+
114+ tempFile = writer
112115
113116 _ , err = tempFile .Write (audioBytes )
114117 require .NoError (t , err )
115118
116119 _ , err = tempFile .Seek (0 , io .SeekStart )
117120 require .NoError (t , err )
121+
122+ t .Cleanup (func () {
123+ _ = tempFile .Close ()
124+ })
118125 }
119126
120127 // as a simple check we'll now transcribe the audio file we just generated...
@@ -123,7 +130,7 @@ func TestClient_GetAudioSpeech(t *testing.T) {
123130 // now send _it_ back through the transcription API and see if we can get something useful.
124131 transcriptResp , err := transcriptClient .Audio .Transcriptions .New (context .Background (), openai.AudioTranscriptionNewParams {
125132 Model : openai .AudioModel (azureOpenAI .Whisper .Model ),
126- File : tempFile ,
133+ File : & fakeFlacFile { tempFile } ,
127134 ResponseFormat : openai .AudioResponseFormatVerboseJSON ,
128135 Language : openai .String ("en" ),
129136 Temperature : openai .Float (0.0 ),
0 commit comments