1 |
493ff79f
|
みぞ@CrazyBeatCoder
|
package com.mizo0203.timeline.talker;
|
2 |
df4ee0a0
|
みぞ@CrazyBeatCoder
|
|
3 |
6a3fcb6d
|
みぞ@CrazyBeatCoder
|
import com.mizo0203.timeline.talker.util.RuntimeUtil;
|
4 |
|
|
import org.jetbrains.annotations.NotNull;
|
5 |
|
|
|
6 |
493ff79f
|
みぞ@CrazyBeatCoder
|
import java.io.*;
|
7 |
df4ee0a0
|
みぞ@CrazyBeatCoder
|
import java.util.concurrent.ExecutorService;
|
8 |
|
|
import java.util.concurrent.Executors;
|
9 |
|
|
|
10 |
|
|
public class Talker {
|
11 |
|
|
|
12 |
|
|
private static final String AQUESTALK_PI_PATH = "./aquestalkpi/AquesTalkPi";
|
13 |
|
|
|
14 |
|
|
private final ExecutorService mSingleThreadExecutor = Executors.newSingleThreadExecutor();
|
15 |
|
|
|
16 |
6a3fcb6d
|
みぞ@CrazyBeatCoder
|
@NotNull private YukkuriVoice mNextVoice = Talker.YukkuriVoice.REIMU;
|
17 |
|
|
|
18 |
df4ee0a0
|
みぞ@CrazyBeatCoder
|
public Talker() throws IllegalStateException, SecurityException {
|
19 |
|
|
File file = new File(AQUESTALK_PI_PATH);
|
20 |
|
|
if (!file.isFile()) {
|
21 |
6a3fcb6d
|
みぞ@CrazyBeatCoder
|
throw new IllegalStateException(
|
22 |
|
|
file.getPath()
|
23 |
|
|
+ " に AquesTalk Pi がありません。\n"
|
24 |
|
|
+ "https://www.a-quest.com/products/aquestalkpi.html\n"
|
25 |
|
|
+ "からダウンロードしてください。");
|
26 |
df4ee0a0
|
みぞ@CrazyBeatCoder
|
}
|
27 |
|
|
if (!file.canExecute()) {
|
28 |
|
|
throw new IllegalStateException(file.getPath() + " に実行権限がありません。");
|
29 |
|
|
}
|
30 |
|
|
}
|
31 |
|
|
|
32 |
6a3fcb6d
|
みぞ@CrazyBeatCoder
|
public void talkAlternatelyAsync(final String text) {
|
33 |
|
|
mSingleThreadExecutor.submit(
|
34 |
|
|
new Runnable() {
|
35 |
|
|
|
36 |
|
|
@Override
|
37 |
|
|
public void run() {
|
38 |
|
|
try {
|
39 |
|
|
File file = new File("text.txt");
|
40 |
|
|
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
|
41 |
|
|
pw.println(text);
|
42 |
|
|
pw.flush();
|
43 |
|
|
pw.close();
|
44 |
|
|
RuntimeUtil.execute(
|
45 |
|
|
new String[] {
|
46 |
|
|
AQUESTALK_PI_PATH, "-v", mNextVoice.value, "-f", "text.txt", "-o", "out.wav"
|
47 |
|
|
});
|
48 |
|
|
RuntimeUtil.execute(new String[] {"sh", "-c", "aplay < out.wav"}); // 起動コマンドを指定する
|
49 |
|
|
|
50 |
|
|
// 読み上げは、霊夢と魔理沙が交互に行なう
|
51 |
|
|
if (mNextVoice == Talker.YukkuriVoice.REIMU) {
|
52 |
|
|
mNextVoice = Talker.YukkuriVoice.MARISA;
|
53 |
|
|
} else {
|
54 |
|
|
mNextVoice = Talker.YukkuriVoice.REIMU;
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
Thread.sleep(2000);
|
58 |
|
|
} catch (@NotNull IOException | InterruptedException e) {
|
59 |
|
|
e.printStackTrace();
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
});
|
63 |
df4ee0a0
|
みぞ@CrazyBeatCoder
|
}
|
64 |
|
|
|
65 |
6a3fcb6d
|
みぞ@CrazyBeatCoder
|
public enum YukkuriVoice {
|
66 |
79a6e367
|
みぞ@CrazyBeatCoder
|
|
67 |
6a3fcb6d
|
みぞ@CrazyBeatCoder
|
/** ゆっくりボイス - 霊夢 */
|
68 |
df4ee0a0
|
みぞ@CrazyBeatCoder
|
REIMU("f1"), //
|
69 |
79a6e367
|
みぞ@CrazyBeatCoder
|
|
70 |
6a3fcb6d
|
みぞ@CrazyBeatCoder
|
/** ゆっくりボイス - 魔理沙 */
|
71 |
df4ee0a0
|
みぞ@CrazyBeatCoder
|
MARISA("f2"), //
|
72 |
|
|
;
|
73 |
|
|
|
74 |
|
|
private final String value;
|
75 |
|
|
|
76 |
6a3fcb6d
|
みぞ@CrazyBeatCoder
|
YukkuriVoice(String value) {
|
77 |
df4ee0a0
|
みぞ@CrazyBeatCoder
|
this.value = value;
|
78 |
|
|
}
|
79 |
|
|
}
|
80 |
|
|
}
|