-
Notifications
You must be signed in to change notification settings - Fork 1
/
text_to_phoneme_id.go
98 lines (91 loc) · 1.39 KB
/
text_to_phoneme_id.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
91
92
93
94
95
96
97
98
package main
import (
"fmt"
"os"
"strings"
voicevoxcorego "github.com/sh1ma/voicevoxcore.go"
)
var PHONEME []string = []string{
"pau",
"A",
"E",
"I",
"N",
"O",
"U",
"a",
"b",
"by",
"ch",
"cl",
"d",
"dy",
"e",
"f",
"g",
"gw",
"gy",
"h",
"hy",
"i",
"j",
"k",
"kw",
"ky",
"m",
"my",
"n",
"ny",
"o",
"p",
"py",
"r",
"ry",
"s",
"sh",
"t",
"ts",
"ty",
"u",
"v",
"w",
"y",
"z",
}
func phonemeIndexOf(phoneme string) int {
for i, v := range PHONEME {
if phoneme == v {
return i
}
}
return -1
}
// nolint:errcheck
func main() {
args := os.Args
if len(args) < 2 {
fmt.Println("usage:\n\tgo run phonemeid.go [ text ]")
os.Exit(127)
}
textSlice := args[1:]
text := strings.Join(textSlice, " ")
core := voicevoxcorego.New()
initializeOptions := voicevoxcorego.NewVoicevoxInitializeOptions(0, 0, false, "./open_jtalk_dic_utf_8-1.11")
core.Initialize(initializeOptions)
defer core.Finalize()
core.LoadModel(1) // ずんだもん
// audioQueryを発行
audioQueryOptions := voicevoxcorego.NewVoicevoxAudioQueryOptions(false)
query, err := core.AudioQuery(text, 1, audioQueryOptions)
if err != nil {
fmt.Println(err)
}
for _, phrase := range query.AccentPharases {
for _, mora := range phrase.Moras {
if mora.Consonant != "" {
fmt.Printf("%d ", phonemeIndexOf(mora.Consonant))
}
fmt.Printf("%d ", phonemeIndexOf(mora.Vowel))
}
}
}