64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package ai
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseBailianTTSOutputSettingsDefaults(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
params map[string]json.RawMessage
|
|
wantFormat string
|
|
wantRate int
|
|
wantErr bool
|
|
}{
|
|
{name: "missing settings defaults to internal PCM16", wantFormat: ttsOutputFormatPCM, wantRate: internalPCM16SampleRate},
|
|
{
|
|
name: "explicit PCM without rate defaults to internal rate",
|
|
params: map[string]json.RawMessage{"format": json.RawMessage(`"pcm"`)},
|
|
wantFormat: ttsOutputFormatPCM,
|
|
wantRate: internalPCM16SampleRate,
|
|
},
|
|
{
|
|
name: "missing format preserves configured PCM rate",
|
|
params: map[string]json.RawMessage{"sample_rate": json.RawMessage(`8000`)},
|
|
wantFormat: ttsOutputFormatPCM,
|
|
wantRate: 8000,
|
|
},
|
|
{
|
|
name: "explicit WAV derives source rate from container",
|
|
params: map[string]json.RawMessage{"format": json.RawMessage(`"wav"`)},
|
|
wantFormat: ttsOutputFormatWAV,
|
|
},
|
|
{
|
|
name: "explicit MP3 derives source rate from bitstream",
|
|
params: map[string]json.RawMessage{"format": json.RawMessage(`"mp3"`)},
|
|
wantFormat: ttsOutputFormatMP3,
|
|
},
|
|
{
|
|
name: "explicit unknown format remains invalid",
|
|
params: map[string]json.RawMessage{"format": json.RawMessage(`"ogg"`)},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
format, rate, err := parseBailianTTSOutputSettings(tt.params)
|
|
if tt.wantErr {
|
|
if err == nil {
|
|
t.Fatal("invalid TTS settings were accepted")
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if format != tt.wantFormat || rate != tt.wantRate {
|
|
t.Fatalf("settings = (%q, %d), want (%q, %d)", format, rate, tt.wantFormat, tt.wantRate)
|
|
}
|
|
})
|
|
}
|
|
}
|