-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartTTS.go
63 lines (49 loc) · 1.33 KB
/
StartTTS.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
package main
import (
"fmt"
"os"
"runtime"
"github.com/kmc-jp/GoogleHomeNotifier/voicevox"
)
type TtsOutputAttr struct {
FilePath string
Error error
}
func StartTTS(settings VoicevoxSetting) (chan string, chan TtsOutputAttr, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err := voicevox.Initialize(voicevox.VoicevoxInitializeOptions{
AccelerationMode: voicevox.VOICEVOX_ACCELERATION_MODE_AUTO,
CpuNumThreads: 0,
LoadAllModels: false,
OpenJtalkDictDir: settings.OpenJtalkDictDir,
})
if err != nil {
return nil, nil, fmt.Errorf("Initialize: %v", err)
}
err = voicevox.LoadModel(settings.SpeakerID)
if err != nil {
return nil, nil, fmt.Errorf("LoadModel: %v", err)
}
var inputchan = make(chan string)
var outputchan = make(chan TtsOutputAttr)
go func() {
for text := range inputchan {
output, err := voicevox.TTS(text, 3, voicevox.VoicevoxTtsOptions{Kana: false})
if err != nil {
outputchan <- TtsOutputAttr{Error: fmt.Errorf("TTS: %v", err)}
continue
}
f, err := os.CreateTemp("", "GoogleHomeSound*.wav")
if err != nil {
outputchan <- TtsOutputAttr{Error: fmt.Errorf("Create: %v", err)}
continue
}
f.Write(output)
f.Close()
voicevox.WavFree(output)
outputchan <- TtsOutputAttr{FilePath: f.Name()}
}
}()
return inputchan, outputchan, nil
}