-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCase.java
124 lines (106 loc) · 4.28 KB
/
TestCase.java
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (c) 2024 by Naohide Sano, All rights reserved.
*
* Programmed by Naohide Sano
*/
package vavi.speech.rpc.jsapi2;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import javax.speech.Engine;
import javax.speech.EngineManager;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerMode;
import javax.speech.synthesis.SynthesizerProperties;
import javax.speech.synthesis.Voice;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import vavi.speech.rpc.jsapi2.client.RpcClient;
import vavi.speech.rpc.jsapi2.client.RpcSynthesizer;
import vavi.speech.rpc.jsapi2.client.RpcSynthesizerMode;
import vavi.util.Debug;
import vavi.util.properties.annotation.Property;
import vavi.util.properties.annotation.PropsEntity;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
/**
* TestCase.
*
* @author <a href="mailto:umjammer@gmail.com">Naohide Sano</a> (nsano)
* @version 0.00 2024-03-02 nsano initial version <br>
*/
@PropsEntity(url = "file:local.properties")
@EnabledIf("localPropertiesExists")
class TestCase {
static boolean localPropertiesExists() {
return Files.exists(Paths.get("local.properties"));
}
@Property(name = "text")
String text = "src/test/resources/test.txt";
@BeforeEach
void setup() throws Exception {
if (localPropertiesExists()) {
PropsEntity.Util.bind(this);
}
}
@Test
void test01() throws Exception {
RpcClient c = new RpcClient();
Debug.println("to getVoices");
Voice[] voices = c.getVoices("vavi.speech.aquestalk10.jsapi2.AquesTalk10SynthesizerMode");
Arrays.stream(voices).forEach(System.err::println);
c.close();
}
@Test
void test02() throws Exception {
EngineManager.registerEngineListFactory(vavi.speech.aquestalk10.jsapi2.AquesTalk10EngineListFactory.class.getName());
Synthesizer synthesizer = (Synthesizer) EngineManager.createEngine(SynthesizerMode.DEFAULT);
Voice[] voices = ((SynthesizerMode) synthesizer.getEngineMode()).getVoices();
Arrays.stream(voices).forEach(System.err::println);
}
@Test
void test03() throws Exception {
speak("ゆっくりしていってね。");
}
@Test
void test04() throws Exception {
RpcClient c = new RpcClient();
SynthesizerProperties sp = c.getSynthesizerProperties();
Debug.println(sp);
c.close();
}
@Test
void test1() throws Exception {
Path path = Paths.get(text);
String text = String.join("\n", Files.readAllLines(path));
speak(text);
}
/** */
void speak(String text) throws Exception {
String modeName = "vavi.speech.aquestalk10.jsapi2.AquesTalk10SynthesizerMode";
// String modeName = "vavi.speech.googlecloud.jsapi2.GoogleCloudTextToSpeechSynthesizerMode"; // TODO env and not work
// String modeName = "vavi.speech.voicevox.jsapi2.VoiceVoxSynthesizerMode";
// String modeName = "vavi.speech.gyutan.jsapi2.GyutanSynthesizerMode"; // TODO not work
Synthesizer synthesizer = (Synthesizer) EngineManager.createEngine(new RpcSynthesizerMode(modeName));
assertInstanceOf(RpcSynthesizer.class, synthesizer);
synthesizer.addSynthesizerListener(System.err::println);
synthesizer.allocate();
synthesizer.waitEngineState(Engine.ALLOCATED);
synthesizer.resume();
synthesizer.waitEngineState(Synthesizer.RESUMED);
String voiceName = "F1";
// String voiceName = "ずんだもん(ノーマル)";
// String voiceName = "ja-JP-Wavenet-B";
Voice voice = Arrays.stream(((SynthesizerMode) synthesizer.getEngineMode()).getVoices()).filter(v -> v.getName().equals(voiceName)).findFirst().get();
Debug.println(voice);
synthesizer.getSynthesizerProperties().setVoice(voice);
synthesizer.getSynthesizerProperties().setVolume(2);
for (String line : text.split("[。\n]")) {
System.out.println(line);
synthesizer.speak(line + "。", System.err::println);
}
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY); // TODO long text cause jersey timeout default 30000ms?
synthesizer.deallocate();
}
}