-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeech_test.go
60 lines (46 loc) · 1.89 KB
/
speech_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
57
58
59
60
package groq_test
import (
"os"
"testing"
"github.com/grqphical/groq"
"github.com/joho/godotenv"
"github.com/stretchr/testify/assert"
)
func TestTranscription(t *testing.T) {
godotenv.Load(".env")
apiKey := os.Getenv("GROQ_TOKEN")
if apiKey == "" {
assert.Fail(t, "API key not set. Make sure you have an environment vairable (or .env file) with GROQ_TOKEN set to your API key")
return
}
client, err := groq.NewGroqClient(apiKey)
assert.NoError(t, err, "the API key should be valid. double check you have set the environment variable correctly")
assert.NoError(t, err)
transcription, err := client.TranscribeAudio("testdata/testAudio.mp3", "whisper-large-v3", nil)
assert.NoError(t, err)
assert.Equal(t, " The quick brown fox jumped over the lazy dog.", transcription.Text)
// test text responses
transcription, err = client.TranscribeAudio("testdata/testAudio.mp3", "whisper-large-v3", &groq.TranscriptionConfig{
ResponseFormat: "text",
})
assert.NoError(t, err)
assert.Equal(t, " The quick brown fox jumped over the lazy dog.", transcription.Text)
}
func TestTranslation(t *testing.T) {
godotenv.Load(".env")
apiKey := os.Getenv("GROQ_TOKEN")
if apiKey == "" {
assert.Fail(t, "API key not set. Make sure you have an environment vairable (or .env file) with GROQ_TOKEN set to your API key")
return
}
client, err := groq.NewGroqClient(apiKey)
assert.NoError(t, err, "the API key should be valid. double check you have set the environment variable correctly")
assert.NoError(t, err)
transcription, err := client.TranslateAudio("testdata/testFrenchAudio.mp3", "whisper-large-v3", nil)
assert.NoError(t, err)
assert.Equal(t, " Hello, how are you?", transcription.Text)
// test text responses
transcription, err = client.TranslateAudio("testdata/testFrenchAudio.mp3", "whisper-large-v3", nil)
assert.NoError(t, err)
assert.Equal(t, " Hello, how are you?", transcription.Text)
}