我正在使用freeTTS库将文本转换为语音.我可以使用这个库编写代码,我可以使用以下代码播放特定文本的语音:
Voice voice = VoiceManager.getInstance().getVoice("kevin16");
if (voice != null) {
voice.allocate();
}
voice.speak("Hello world");
Run Code Online (Sandbox Code Playgroud)
当tts lib完成说话过程时,是否有一种方法可以获得回调?
我自己找到了答案。当库完成发言过程时,我们不需要回调。仅当讲话过程结束时,控件才会转到下一行。
我就是这样做的:
Thread t = new Thread() {
@Override
public void run() {
super.run();
try {
voice = initializeTTS(); // a func to initialize TTS lib.
voice.speak("Hello world");
// do whatever you want to do from here only.
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
Run Code Online (Sandbox Code Playgroud)