-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeechtotext_test.go
More file actions
67 lines (57 loc) · 1.45 KB
/
speechtotext_test.go
File metadata and controls
67 lines (57 loc) · 1.45 KB
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
61
62
63
64
65
66
67
package elevenlabs
import (
"context"
"testing"
)
func TestTranscriptionRequestValidation(t *testing.T) {
client, _ := NewClient()
ctx := context.Background()
// Test empty request
_, err := client.SpeechToText().Transcribe(ctx, &TranscriptionRequest{})
if err == nil {
t.Error("Transcribe() with empty request should return error")
}
var valErr *ValidationError
if !isValidationError(err, &valErr) {
t.Errorf("Expected ValidationError, got %T", err)
}
}
func TestSpeechToTextService(t *testing.T) {
apiKey := getAPIKey(t)
client, err := NewClient(WithAPIKey(apiKey))
if err != nil {
t.Fatalf("NewClient() error = %v", err)
}
// Test that service is accessible
if client.SpeechToText() == nil {
t.Error("SpeechToText() returned nil")
}
}
func TestTranscriptionResponse(t *testing.T) {
// Test response struct initialization
resp := &TranscriptionResponse{
Text: "Hello world",
LanguageCode: "en",
Words: []TranscriptionWord{
{Text: "Hello", Start: 0.0, End: 0.5},
{Text: "world", Start: 0.6, End: 1.0},
},
}
if resp.Text != "Hello world" {
t.Errorf("Text = %s, want Hello world", resp.Text)
}
if len(resp.Words) != 2 {
t.Errorf("Words count = %d, want 2", len(resp.Words))
}
}
// Helper to check if error is ValidationError
func isValidationError(err error, valErr **ValidationError) bool {
if err == nil {
return false
}
v, ok := err.(*ValidationError)
if ok && valErr != nil {
*valErr = v
}
return ok
}