-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaudio_test.go
56 lines (52 loc) · 1.45 KB
/
audio_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package openai
import (
"bytes"
"context"
"io"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAudio(t *testing.T) {
testCases := []struct {
name string
filename string
wantTranscription string
wantTranslation string
}{
{
name: "german",
filename: "testdata/german.wav",
wantTranscription: "Ich will das eben wegbringen und dann mit Karl was trinken gehen.",
wantTranslation: "I just want to take this away and go out for a drink with Karl.",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
e := New(os.Getenv("OPENAI_KEY"))
file, err := os.Open(tc.filename)
assert.NoError(t, err)
defer file.Close()
buffer, err := io.ReadAll(file)
assert.NoError(t, err)
audioOpts := &AudioOptions{
AudioFormat: strings.Split(tc.filename, ".")[1],
Model: ModelWhisper,
Temperature: 0,
}
t.Run("transcribe", func(t *testing.T) {
audioOpts.File = bytes.NewBuffer(buffer)
r, err := e.Transcribe(context.Background(), &TranscribeOptions{AudioOptions: audioOpts})
assert.NoError(t, err)
assert.Equal(t, tc.wantTranscription, r.Text)
})
t.Run("translate", func(t *testing.T) {
audioOpts.File = bytes.NewBuffer(buffer)
r, err := e.Translate(context.Background(), &TranslateOptions{AudioOptions: audioOpts})
assert.NoError(t, err)
assert.Equal(t, tc.wantTranslation, r.Text)
})
})
}
}