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