本文整理汇总了Java中android.speech.tts.TextToSpeech.OnUtteranceCompletedListener类的典型用法代码示例。如果您正苦于以下问题:Java OnUtteranceCompletedListener类的具体用法?Java OnUtteranceCompletedListener怎么用?Java OnUtteranceCompletedListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OnUtteranceCompletedListener类属于android.speech.tts.TextToSpeech包,在下文中一共展示了OnUtteranceCompletedListener类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener; //导入依赖的package包/类
public static void initialize(Context context, final SpeechResource resource, final Callback<String> callback){
AudioTextAdapter.tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
tts.setLanguage(resource.getLang());
tts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener(){
@Override
public void onUtteranceCompleted(String utteranceId) {
System.out.println("Utterance completed: "+(stopped? "STOPPED" : "FINISHED"));
if(!stopped)
listener.completed();
}
});
callback.callback("Text to speech engine correctly initialized", null);
}else{
callback.callback(null, new Exception("Error initializing text to text to speech engine"));
}
}
});
}
示例2: onHighlight
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener; //导入依赖的package包/类
public void onHighlight(String word, SpannableString text) {
tv1.setText(text);
HashMap<String, String> params = new HashMap<String, String>();
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, word);
tts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {
public void onUtteranceCompleted(String utteranceId) {
runOnUiThread(new Runnable() {
public void run() {
if (highlighter1.hasNext()) {
highlighter1.highlightNext();
} else {
highlighter1.reset();
}
}
});
}
});
tts.speak(word, TextToSpeech.QUEUE_ADD, params);
}
示例3: setOnUtteranceCompletedListener
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener; //导入依赖的package包/类
@Override
public int setOnUtteranceCompletedListener(
OnUtteranceCompletedListener listener) {
if (tts == null) {
return super.setOnUtteranceCompletedListener(listener);
}
return tts.setOnUtteranceCompletedListener(listener);
}
示例4: testRun
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener; //导入依赖的package包/类
public void testRun() throws Exception {
// Expect service data calls
TripStatistics stats = new TripStatistics();
// Expect announcement building call
expect(mockTask.getAnnouncement(same(stats))).andStubReturn(ANNOUNCEMENT);
// Put task in "ready" state
startTask(TextToSpeech.SUCCESS);
expect(tts.isLanguageAvailable(DEFAULT_LOCALE)).andStubReturn(TextToSpeech.LANG_AVAILABLE);
expect(tts.setLanguage(DEFAULT_LOCALE)).andReturn(TextToSpeech.LANG_AVAILABLE);
expect(tts.setSpeechRate(AnnouncementPeriodicTask.TTS_SPEECH_RATE)).andReturn(
TextToSpeech.SUCCESS);
expect(tts.setOnUtteranceCompletedListener((OnUtteranceCompletedListener) EasyMock.anyObject()))
.andReturn(0);
// Expect actual announcement call
expect(
tts.speak(eq(ANNOUNCEMENT), eq(TextToSpeech.QUEUE_FLUSH),
eq(AnnouncementPeriodicTask.SPEECH_PARAMS))).andReturn(0);
// Run the announcement
AndroidMock.replay(tts);
task.announce(stats);
AndroidMock.verify(mockTask, tts);
}
示例5: onResume
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
destroyTTS();
tts = new TextToSpeech(this, this);
tts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {
@Override
public void onUtteranceCompleted(String utteranceId) {
onTTSCompleted();
}
});
announceHelp();
}
示例6: setTtsOnUtteranceProgressListener
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener; //导入依赖的package包/类
public void setTtsOnUtteranceProgressListener(TextToSpeech tts) {
tts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {
@Override
public void onUtteranceCompleted(String utteranceId) {
if (ReadText.sTextQueue.size() > 0) {
String[] text = ReadText.sTextQueue.remove(0);
ReadText.speak(text[0], text[1], TextToSpeech.QUEUE_FLUSH);
}
}
});
}
示例7: onInit
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener; //导入依赖的package包/类
public void onInit(int Status)
{
/* Ensure that the text-to-speech engine is active before
* continuing. */
if (Status != TextToSpeech.SUCCESS)
{
handleInitFailure();
return;
}
/* Attempt to load the default voice */
Locale Language = Locale.getDefault();
if (Language == null)
{
Log.w(TAG, "No default language, using US English");
Language = Locale.US;
}
/* If the voice failed, then give up. */
int Result = m_TextToSpeech.setLanguage(Language);
if ((Result == TextToSpeech.LANG_MISSING_DATA) ||
(Result == TextToSpeech.LANG_NOT_SUPPORTED))
{
handleInitFailure();
return;
}
/* Load the string to speak. */
String ToSpeak = m_Preferences.speechText();
if ((ToSpeak != null) && (ToSpeak.length() > 0))
{
/* Handle audio track once the speech is complete. */
m_TextToSpeech.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener()
{
public void onUtteranceCompleted(String UtteranceID)
{
Log.d(TAG, "Utterance complete!");
m_AudioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);
m_GUI.finish();
}
});
/* Set parameters */
HashMap<String, String> Parameters = new HashMap<String, String>();
/* Use default utterance ID. */
Parameters.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, UTTERANCE_ID);
/* Use the voice call audio stream. */
Parameters.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_VOICE_CALL));
/* Mute the music channel. */
m_AudioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
/* Speak the text. */
m_TextToSpeech.speak(ToSpeak, TextToSpeech.QUEUE_ADD, Parameters);
/* Clear the text to prevent it from being spoken again. */
m_Preferences.clearSpeechText();
}
}