Skip to content

Commit 12b7693

Browse files
author
ynn
committed
should_skip_non_japanese config for VOICEVOX.
1 parent 9892bf4 commit 12b7693

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

config/config.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ type CoefontConfig struct {
1313
}
1414

1515
type VoicevoxConfig struct {
16-
Enabled bool `json:"enabled"`
17-
ShouldSkipEnglish bool `json:"should_skip_english"`
18-
APIKey string `json:"api_key"`
19-
URL string `json:"url"`
20-
Speaker string `json:"speaker"`
21-
Speed float64 `json:"speed"`
16+
Enabled bool `json:"enabled"`
17+
ShouldSkipNonJapanese bool `json:"should_skip_non_japanese"`
18+
APIKey string `json:"api_key"`
19+
URL string `json:"url"`
20+
Speaker string `json:"speaker"`
21+
Speed float64 `json:"speed"`
2222
}
2323

2424
type ReadlineConfig struct {

main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import "os"
99
import "strings"
1010

1111
import "github.com/chzyer/readline"
12-
import "golang.org/x/exp/utf8string"
1312

1413
import "coefontuber/coefont"
1514
import "coefontuber/voicevox"
1615
import "coefontuber/config"
1716
import "coefontuber/play"
17+
import "coefontuber/util"
1818

1919
const (
2020
configFile = "./config.json"
@@ -149,7 +149,7 @@ func main() {
149149
var resultChannel = make(chan string)
150150

151151
if config.Voicevox.Enabled { //VOICEVOX
152-
if config.Voicevox.ShouldSkipEnglish && utf8string.NewString(line).IsASCII() {
152+
if config.Voicevox.ShouldSkipNonJapanese && !util.IsJapanese(line) {
153153
fmt.Println()
154154
continue
155155
}

template_config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"voicevox": {
99
"enabled": false,
10-
"should_skip_english": true,
10+
"should_skip_non_japanese": true,
1111
"url": "https://api.su-shiki.com/v2/voicevox/audio/",
1212
"api_key": "U3PxH58855e999O",
1313
"speaker": "a8cc6d22-aad0-4ab8-bf1e-2f843924164a",

util/util.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package util
2+
3+
import "unicode"
4+
5+
func IsJapanese(s string) bool {
6+
for _, c := range s {
7+
if unicode.In(c, unicode.Hiragana, unicode.Katakana, unicode.Han) {
8+
return true
9+
}
10+
11+
}
12+
return false
13+
}

util/util_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package util
2+
3+
import "testing"
4+
5+
func f(t *testing.T, s string, expected bool) {
6+
if IsJapanese(s) != expected {
7+
t.Fatal(s)
8+
}
9+
}
10+
11+
func Test(t *testing.T) {
12+
f(t, "hello", false)
13+
f(t, "342352", false)
14+
f(t, "🌙", false)
15+
f(t, "사랑합니다", false)
16+
f(t, "01234", false)
17+
f(t, "defgh", false)
18+
19+
f(t, "你好", true)
20+
f(t, "あ", true)
21+
f(t, "ABCコンテスト", true)
22+
f(t, "表現", true)
23+
}

0 commit comments

Comments
 (0)