-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspeech_test.go
90 lines (80 loc) · 2.98 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package edgetts
import (
"archive/zip"
"os"
"testing"
)
func TestSpeech_StartTasks(t *testing.T) {
opts := make([]Option, 0)
opts = append(opts, WithVoice("zh-CN-YunxiaNeural"))
speech, err := NewSpeech(opts...)
if err != nil {
t.Fatal(err)
}
audio, err := os.OpenFile("testdata/test.mp3", os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
t.Fatal(err)
}
err = speech.AddSingleTask("种一棵树最好的时间是十年前,其次是现在.The best time to plant a tree is 20 years ago. The second-best time is now.", audio)
if err != nil {
t.Fatal(err)
}
audio2, err := os.OpenFile("testdata/test1.mp3", os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
t.Fatal(err)
}
err = speech.AddSingleTask("莫听穿林打叶声,何妨吟啸且徐行。竹杖芒鞋轻胜马,谁怕?一蓑烟雨任平生。料峭春风吹酒醒,微冷,山头斜照却相迎。回首向来萧瑟处,归去,也无风雨也无晴。", audio2)
if err != nil {
t.Fatal(err)
}
speech.StartTasks()
}
func TestSpeech_StartTasksToZip(t *testing.T) {
opts := make([]Option, 0)
opts = append(opts, WithVoice("zh-CN-YunxiaNeural"))
speech, err := NewSpeech(opts...)
if err != nil {
t.Fatal(err)
}
w, err := os.OpenFile("testdata/tts.zip", os.O_RDWR|os.O_CREATE, 0666)
zipWriter := zip.NewWriter(w)
defer zipWriter.Close()
dataPayload := make(map[string]string)
dataPayload["test.mp3"] = "种一棵树最好的时间是十年前,其次是现在.The best time to plant"
dataPayload["test1.mp3"] = "莫听穿林打叶声,何妨吟啸且徐行.。竹杖芒鞋轻胜马,谁怕?一蓑烟雨任平生。料峭春风吹酒醒,微冷,山头斜照却相迎。回首向来萧瑟处,归去,也无风雨也无晴。"
speech.AddPackTask(dataPayload, zipWriter.Create, w)
speech.StartTasks()
zipWriter.Flush()
}
func TestSpeech_StartTasksWithOptionsToZip(t *testing.T) {
opts := make([]Option, 0)
opts = append(opts, WithVoice("zh-CN-YunxiaNeural"))
speech, err := NewSpeech(opts...)
if err != nil {
t.Fatal(err)
}
w, err := os.OpenFile("testdata/tts.zip", os.O_RDWR|os.O_CREATE, 0666)
zipWriter := zip.NewWriter(w)
defer zipWriter.Close()
dataPayload := make(map[string]string)
dataPayload["test.mp3"] = "种一棵树最好的时间是十年前,其次是现在.The best time to plant"
dataPayload["test1.mp3"] = "莫听穿林打叶声,何妨吟啸且徐行.。竹杖芒鞋轻胜马,谁怕?一蓑烟雨任平生。料峭春风吹酒醒,微冷,山头斜照却相迎。回首向来萧瑟处,归去,也无风雨也无晴。"
options := make(map[string][]Option)
options["test.mp3"] = []Option{WithVoice("zh-CN-YunyangNeural")}
speech.AddPackTaskWithCustomOptions(dataPayload, options, zipWriter.Create, w)
speech.StartTasks()
zipWriter.Flush()
}
func TestSpeech_GetVoiceList(t *testing.T) {
speech, err := NewSpeech()
if err != nil {
t.Fatal(err)
}
voices, err := speech.GetVoiceList()
if err != nil {
t.Fatal(err)
}
for _, voice := range voices {
t.Logf("voice: %+v", voice)
}
}