Created
December 1, 2015 12:04
-
-
Save orekyuu/8ca5143a6fdcf4d6e9f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.orekyuu.speak; | |
import am.ik.voicetext4j.EmotionalSpeaker; | |
import net.orekyuu.javatter.api.command.Command; | |
import net.orekyuu.javatter.api.command.CommandManager; | |
import net.orekyuu.javatter.api.plugin.OnInit; | |
import net.orekyuu.javatter.api.plugin.OnPostInit; | |
import net.orekyuu.javatter.api.service.TwitterUserService; | |
import javax.inject.Inject; | |
import java.util.List; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
public class SpeakPlugin { | |
@Inject | |
private CommandManager commandManager; | |
private ExecutorService executor = Executors.newSingleThreadExecutor(runnable -> { | |
Thread thread = new Thread(runnable); | |
thread.setDaemon(true); | |
thread.setName("VoiceTextThread"); | |
return thread; | |
}); | |
@OnInit | |
public void init() { | |
System.setProperty("voicetext.apikey", "ここは秘密"); | |
} | |
@OnPostInit | |
public void preInitialize() { | |
commandManager.registerCommand(new Command() { | |
@Override | |
public String command() { | |
return "say"; | |
} | |
@Override | |
public String help() { | |
return "/say [読み上げる文章]"; | |
} | |
@Override | |
public void exec(List<String> args) { | |
if (args.isEmpty()) { | |
args.add("読み上げる文章がありません。引数に読み上げる文章を与えてください。"); | |
} | |
args.forEach(SpeakPlugin.this::sayText); | |
} | |
}); | |
} | |
private void sayText(String text) { | |
executor.execute(() -> { | |
EmotionalSpeaker.HARUKA.ready() | |
.pitch(105) | |
.speed(105) | |
.speak(text); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment