forked from surfaceyu/edge-tts-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (51 loc) · 1.51 KB
/
main.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
package main
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"github.com/spf13/pflag"
"github.com/surfaceyu/edge-tts-go/edgeTTS"
)
func usage() {
fmt.Println("Microsoft Edge TTS")
pflag.PrintDefaults()
}
func main() {
listVoices := pflag.BoolP("list-voices", "l", false, "lists available voices and exits")
locale := pflag.StringP("locale", "", "", "locale for voice lists ex: zh-CN, en-US")
text := pflag.StringP("text", "t", "", "what TTS will say")
file := pflag.StringP("file", "f", "", "same as --text but read from file")
voice := pflag.StringP("voice", "v", "zh-CN-XiaoxiaoNeural", "voice for TTS")
volume := pflag.String("volume", "+0%", "set TTS volume")
rate := pflag.String("rate", "+0%", "set TTS rate")
writeMedia := pflag.String("write-media", "", "send media output to file instead of stdout")
pitch := pflag.String("pitch", "+0Hz", "set TTS pitch")
// proxy := pflag.String("proxy", "", "use a proxy for TTS and voice list")
pflag.Usage = usage
pflag.Parse()
if *listVoices {
edgeTTS.PrintVoices(*locale)
os.Exit(0)
}
if *file != "" {
if *file == "/dev/stdin" {
reader := bufio.NewReader(os.Stdin)
*text, _ = reader.ReadString('\n')
} else {
data, _ := ioutil.ReadFile(*file)
*text = string(data)
}
}
if *text != "" {
args := edgeTTS.Args{
Text: *text,
Voice: *voice,
Pitch: *pitch,
Rate: *rate,
Volume: *volume,
WriteMedia: *writeMedia,
}
edgeTTS.NewTTS(args).AddText(args.Text, args.Voice, args.Pitch, args.Rate, args.Volume).Speak()
}
}