本文整理匯總了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);
}