本文整理汇总了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");
}
}
}
});
}
示例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;
}
}
});
}
}
});
}
示例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();
}
});
}
});
}
示例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);
}
});
}
示例5: setOnUtteranceProgressListener
import android.speech.tts.UtteranceProgressListener; //导入依赖的package包/类
@Override
public int setOnUtteranceProgressListener(final UtteranceProgressListener listener) {
this.listener = (SaiyProgressListener) listener;
return super.setOnUtteranceProgressListener(listener);
}