-
Notifications
You must be signed in to change notification settings - Fork 1
/
synthesize_test.go
49 lines (42 loc) · 1.01 KB
/
synthesize_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
package azure_tts
import (
"bytes"
"context"
"os"
"testing"
)
var (
subConfig = NewDefaultSubscriptionConfig()
)
func TestSynthesizer(t *testing.T) {
if !subConfig.Valid() {
t.Skip("no config")
}
synthesizer := NewSynthesizer(context.Background(), subConfig)
audioConfig := NewDefaultAudioConfig()
audioConfig.Synthesis.Audio.MetadataOptions.WordBoundaryEnabled = true
synthesizer.SetConfig(audioConfig)
task := synthesizer.SpeakTextAsync("zh-CN", "zh-CN-XiaoxiaoNeural", "Hello, world! 你好,世界!")
audioStream := &bytes.Buffer{}
stop := false
for !stop {
select {
case <-task.Done():
stop = true
case err := <-task.Error:
t.Fatal(err)
case event := <-task.Event:
switch event.(type) {
case *AudioMetadataEvent:
metadata := event.(*AudioMetadataEvent)
for _, item := range metadata.Metadata {
t.Log(item.Type)
t.Log(item.Data)
}
}
case audio := <-task.Audio:
audioStream.Write(audio)
}
}
os.WriteFile("synth.mp3", audioStream.Bytes(), 0644)
}