opt
This commit is contained in:
@@ -2,10 +2,12 @@ package com.mogo.utils.tts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Bundle;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.speech.tts.UtteranceProgressListener;
|
||||
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@@ -16,11 +18,12 @@ import java.util.Locale;
|
||||
*/
|
||||
public class AndroidTTSPlayer extends UtteranceProgressListener implements TTSPlayer, TextToSpeech.OnInitListener {
|
||||
|
||||
private static final String TAG = "AndroidTTSPlayer";
|
||||
|
||||
private TextToSpeech mTtsEngine;
|
||||
private Context mContext;
|
||||
private boolean mIsSuccess = false;
|
||||
private Bundle mParams;
|
||||
private HashMap< String, String > mParams;
|
||||
|
||||
/**
|
||||
* {@link TextToSpeech.Engine#KEY_PARAM_STREAM},
|
||||
@@ -32,9 +35,10 @@ public class AndroidTTSPlayer extends UtteranceProgressListener implements TTSPl
|
||||
public AndroidTTSPlayer( Context context ) {
|
||||
mContext = context.getApplicationContext();
|
||||
mTtsEngine = new TextToSpeech( mContext, this );
|
||||
mParams = new Bundle();
|
||||
mParams.putInt( TextToSpeech.Engine.KEY_PARAM_STREAM, AudioManager.STREAM_ALARM );
|
||||
mParams.putInt( TextToSpeech.Engine.KEY_PARAM_STREAM, AudioManager.STREAM_ALARM );
|
||||
mParams = new HashMap<>();
|
||||
mParams.put( TextToSpeech.Engine.KEY_PARAM_STREAM, AudioManager.STREAM_ALARM + "" );
|
||||
mParams.put( TextToSpeech.Engine.KEY_PARAM_VOLUME, "1" );
|
||||
mParams.put( TextToSpeech.Engine.KEY_PARAM_PAN, "0" );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,7 +50,12 @@ public class AndroidTTSPlayer extends UtteranceProgressListener implements TTSPl
|
||||
|
||||
@Override
|
||||
public void speakTTS( String text ) {
|
||||
// mTtsEngine.speak()
|
||||
if ( !mIsSuccess ) {
|
||||
Logger.d( TAG, "do not support tts play." );
|
||||
return;
|
||||
}
|
||||
mParams.put( TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, text );
|
||||
mTtsEngine.speak( text, TextToSpeech.QUEUE_FLUSH, mParams );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mogo.utils.tts;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-04-14
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class TTSPlayerFactory {
|
||||
|
||||
public static TTSPlayer getPlayer( Context context ) {
|
||||
return new AndroidTTSPlayer( context );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user