当前位置: 首页>>代码示例>>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;未经允许,请勿转载。