當前位置: 首頁>>代碼示例>>Java>>正文


Java UtteranceProgressListener類代碼示例

本文整理匯總了Java中android.speech.tts.UtteranceProgressListener的典型用法代碼示例。如果您正苦於以下問題:Java UtteranceProgressListener類的具體用法?Java UtteranceProgressListener怎麽用?Java UtteranceProgressListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UtteranceProgressListener類屬於android.speech.tts包,在下文中一共展示了UtteranceProgressListener類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Speak

import android.speech.tts.UtteranceProgressListener; //導入依賴的package包/類
public Speak(Activity context) {
	mSpeaking = null;
	mTTS = new TextToSpeech(context.getApplicationContext(), new TextToSpeech.OnInitListener() {
		@Override
		public void onInit(int status) {
			if (status == TextToSpeech.ERROR) {
				Log.e(TAG, "TTS init failed");
			} else if (status == TextToSpeech.SUCCESS) {
				mTTS.setOnUtteranceProgressListener(new UtteranceProgressListener() {
					@Override
					public void onDone(String utteranceId) {
						Log.i(TAG, "TTS complete '" + mSpeaking + "'");
						mTTS.stop();
						mSpeaking = null;
					}

					@Override
					public void onError(String utteranceId) {
						Log.e(TAG, "TTS error");
					}

					@Override
					public void onStart(String utteranceId) {
						Log.i(TAG, "TTS start");
					}
				});

				// TODO: select language from preferences or can I get it from global?
				int result = mTTS.setLanguage(Locale.US);
				if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
					Log.e(TAG, "This Language is not supported");
				}
			}
		}
	});
}
 
開發者ID:tharvey,項目名稱:BlocklyBot,代碼行數:37,代碼來源:Speak.java

示例2: initialize

import android.speech.tts.UtteranceProgressListener; //導入依賴的package包/類
/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 *
 * @param cordova The context of the main Activity.
 * @param webView The CordovaWebView Cordova is running in.
 */
public void initialize(final CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    ttsEngine=new TextToSpeech(cordova.getActivity().getApplication(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
               if(status != TextToSpeech.ERROR) {
  if(ttsEngine == null) return;
            	   ttsEngine.setOnUtteranceProgressListener(new UtteranceProgressListener() {
           			
           			@Override
           			public void onStart(String utteranceId) {
           				Log.d(TAG, "Utterance listener: start");
           			}
           			
           			@Override
           			@Deprecated
           			public void onError(String utteranceId) {
           				Log.e(TAG, "Utterance listener: error");
           			}
           			
           			@SuppressLint("NewApi") @Override
           			public void onDone(String utteranceId) {
           				Log.d(TAG, "Utterance listener: done utterance "+position+", mustStop: "+mustStop);
           				if(!mustStop && position<text.length-1){
           					position++;
           					Log.d(TAG, "Now speacking sentence "+position+" in "+text.length+": \""+text[position]);
           					if(Build.VERSION.SDK_INT>=21) ttsEngine.speak(text[position], TextToSpeech.QUEUE_FLUSH, null, TAG);
           					else ttsEngine.speak(text[position], TextToSpeech.QUEUE_FLUSH, Advtts.utteranceId);
           				} else if(position>=text.length-1) {
           					position=0;
           					mustStop=false;
           				}
           			}
           		});
               }
            }
         });
}
 
開發者ID:GruppoMeta,項目名稱:cordova-plugin-adv-tts,代碼行數:46,代碼來源:Advtts.java

示例3: TextoAVoz

import android.speech.tts.UtteranceProgressListener; //導入依賴的package包/類
/**
 * Constructor de la clase.
 *
 * @param contexto Contexto de la aplicación. En un Activity se debe pasar this.
 * @param callback Encapsula los procedimientos a ejecutar dependiendo del estado del servicio de pronunciación.
 */
public TextoAVoz(final Context contexto, final TTSCallback callback) {
    this.pronunciador = new TextToSpeech(contexto, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int i) {
            callback.servicioEspera();
            pronunciador.setOnUtteranceProgressListener(new UtteranceProgressListener() {
                @Override
                public void onStart(String s) {
                    callback.servicioEjecucion();
                }

                @Override
                public void onDone(String s) {
                    callback.servicioListo();
                }

                @Override
                public void onError(String s) {
                    callback.servicioError();
                }
            });
        }
    });
}
 
開發者ID:josecols,項目名稱:modula,代碼行數:31,代碼來源:TextoAVoz.java

示例4: onCreate

import android.speech.tts.UtteranceProgressListener; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       
       mSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
           @Override
           public void onInit(int status) {
           	final String TAG = "speech";
           	UtteranceProgressListener utteranceProgressListener=new UtteranceProgressListener() {

                   @Override
                   public void onStart(String utteranceId) {
                       Log.d(TAG, "onStart ( utteranceId :"+utteranceId+" ) ");
                   }

                   @Override
                   public void onError(String utteranceId) {
                       Log.d(TAG, "onError ( utteranceId :"+utteranceId+" ) ");
                   }

                   @Override
                   public void onDone(String utteranceId) {
                       Log.d(TAG, "onDone ( utteranceId :"+utteranceId+" ) ");
                       finish();
                   }
               };
               
               mSpeech.setOnUtteranceProgressListener(utteranceProgressListener);

           }
       });
}
 
開發者ID:dintskirveli,項目名稱:glass-btc,代碼行數:33,代碼來源:MainActivity.java

示例5: setOnUtteranceProgressListener

import android.speech.tts.UtteranceProgressListener; //導入依賴的package包/類
@Override
public int setOnUtteranceProgressListener(final UtteranceProgressListener listener) {
    this.listener = (SaiyProgressListener) listener;
    return super.setOnUtteranceProgressListener(listener);
}
 
開發者ID:brandall76,項目名稱:Saiy-PS,代碼行數:6,代碼來源:SaiyTextToSpeech.java


注:本文中的android.speech.tts.UtteranceProgressListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。