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