当前位置: 首页>>代码示例>>Java>>正文


Java OnUtteranceCompletedListener类代码示例

本文整理汇总了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"));
            }
        }
    });
}
 
开发者ID:ericleib,项目名称:blindtale,代码行数:22,代码来源:AudioTextAdapter.java

示例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);

}
 
开发者ID:mpakarlsson,项目名称:ilearnrw,代码行数:26,代码来源:HighlighterActivity.java

示例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);
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:9,代码来源:AnnouncementPeriodicTaskTest.java

示例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);
}
 
开发者ID:Plonk42,项目名称:mytracks,代码行数:28,代码来源:AnnouncementPeriodicTaskTest.java

示例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();
}
 
开发者ID:arthurzaczek,项目名称:launcherforblind,代码行数:16,代码来源:AbstractActivity.java

示例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);
            }
        }
    });
}
 
开发者ID:ankidroid,项目名称:Anki-Android,代码行数:12,代码来源:CompatV10.java

示例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();
       }
}
 
开发者ID:zachrattner,项目名称:pockettalk,代码行数:62,代码来源:SpeechActivity.java


注:本文中的android.speech.tts.TextToSpeech.OnUtteranceCompletedListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。