リビジョン 6a3fcb6d
みぞ @mizo0203 さんが7年以上前に追加
| src/com/mizo0203/timeline/talker/Talker.java | ||
|---|---|---|
| 1 | 1 |
package com.mizo0203.timeline.talker; |
| 2 | 2 |
|
| 3 |
import com.mizo0203.timeline.talker.util.RuntimeUtil; |
|
| 4 |
import org.jetbrains.annotations.NotNull; |
|
| 5 |
|
|
| 3 | 6 |
import java.io.*; |
| 4 | 7 |
import java.util.concurrent.ExecutorService; |
| 5 | 8 |
import java.util.concurrent.Executors; |
| ... | ... | |
| 10 | 13 |
|
| 11 | 14 |
private final ExecutorService mSingleThreadExecutor = Executors.newSingleThreadExecutor(); |
| 12 | 15 |
|
| 16 |
@NotNull private YukkuriVoice mNextVoice = Talker.YukkuriVoice.REIMU; |
|
| 17 |
|
|
| 13 | 18 |
public Talker() throws IllegalStateException, SecurityException {
|
| 14 | 19 |
File file = new File(AQUESTALK_PI_PATH); |
| 15 | 20 |
if (!file.isFile()) {
|
| 16 |
throw new IllegalStateException(file.getPath() + " に AquesTalk Pi がありません。\n" |
|
| 17 |
+ "https://www.a-quest.com/products/aquestalkpi.html\n" + "からダウンロードしてください。"); |
|
| 21 |
throw new IllegalStateException( |
|
| 22 |
file.getPath() |
|
| 23 |
+ " に AquesTalk Pi がありません。\n" |
|
| 24 |
+ "https://www.a-quest.com/products/aquestalkpi.html\n" |
|
| 25 |
+ "からダウンロードしてください。"); |
|
| 18 | 26 |
} |
| 19 | 27 |
if (!file.canExecute()) {
|
| 20 | 28 |
throw new IllegalStateException(file.getPath() + " に実行権限がありません。"); |
| 21 | 29 |
} |
| 22 | 30 |
} |
| 23 | 31 |
|
| 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 |
}); |
|
| 32 |
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 |
}); |
|
| 45 | 63 |
} |
| 46 | 64 |
|
| 47 |
public static enum YukkuriVoice {
|
|
| 65 |
public enum YukkuriVoice {
|
|
| 48 | 66 |
|
| 49 |
/** |
|
| 50 |
* ゆっくりボイス - 霊夢 |
|
| 51 |
*/ |
|
| 67 |
/** ゆっくりボイス - 霊夢 */ |
|
| 52 | 68 |
REIMU("f1"), //
|
| 53 | 69 |
|
| 54 |
/** |
|
| 55 |
* ゆっくりボイス - 魔理沙 |
|
| 56 |
*/ |
|
| 70 |
/** ゆっくりボイス - 魔理沙 */ |
|
| 57 | 71 |
MARISA("f2"), //
|
| 58 | 72 |
; |
| 59 | 73 |
|
| 60 | 74 |
private final String value; |
| 61 | 75 |
|
| 62 |
private YukkuriVoice(String value) {
|
|
| 76 |
YukkuriVoice(String value) {
|
|
| 63 | 77 |
this.value = value; |
| 64 | 78 |
} |
| 65 | 79 |
} |
| 66 |
|
|
| 67 | 80 |
} |
他の形式にエクスポート: Unified diff
Add feature Mastodon's timeline talking. fix #422 @16.0h