use of com.baidu.tts.client.SpeechSynthesizerListener in project AnkiChinaAndroid by ankichinateam.
the class MySyntherizer method init.
/**
* 注意该方法需要在新线程中调用。且该线程不能结束。详细请参见NonBlockSyntherizer的实现
*
* @param config 配置
* @return 是否初始化成功
*/
protected boolean init(InitConfig config) {
sendToUiThread("初始化开始");
mSpeechSynthesizer = SpeechSynthesizer.getInstance();
mSpeechSynthesizer.setContext(context);
Log.i("MySyntherizer", "包名:" + context.getPackageName());
SpeechSynthesizerListener listener = config.getListener();
// listener = new SwitchSpeakerListener(mainHandler,context,this); // 测试播放过程中切换发音人逻辑
mSpeechSynthesizer.setSpeechSynthesizerListener(listener);
// 请替换为语音开发者平台上注册应用得到的App ID ,AppKey ,Secret Key ,填写在SynthActivity的开始位置
mSpeechSynthesizer.setAppId(config.getAppId());
mSpeechSynthesizer.setApiKey(config.getAppKey(), config.getSecretKey());
setParams(config.getParams());
// 初始化tts
int result = mSpeechSynthesizer.initTts(config.getTtsMode());
if (result != 0) {
sendToUiThread("【error】initTts 初始化失败 + errorCode:" + result);
return false;
}
// 设置播放的音频流类型,具体参数和组合见AudioAttributes,https://source.android.google.cn/devices/audio/attributes
// mSpeechSynthesizer.setAudioAttributes(AudioAttributes.USAGE_MEDIA,AudioAttributes.CONTENT_TYPE_MUSIC);
// 此时可以调用 speak和synthesize方法
sendToUiThread(INIT_SUCCESS, "合成引擎初始化成功");
return true;
}
use of com.baidu.tts.client.SpeechSynthesizerListener in project AnkiChinaAndroid by ankichinateam.
the class AbstractFlashcardViewer method initBDTTs.
private void initBDTTs() {
appId = Auth.getInstance(this).getAppId();
appKey = Auth.getInstance(this).getAppKey();
secretKey = Auth.getInstance(this).getSecretKey();
// 离线合成SDK必须有此参数;在线合成SDK没有此参数
sn = Auth.getInstance(this).getSn();
// 日志打印在logcat中
LoggerProxy.printable(true);
String tmpDir = FileUtil.createTmpDir(this);
// 设置初始化参数
// 此处可以改为 含有您业务逻辑的SpeechSynthesizerListener的实现类
SpeechSynthesizerListener listener = new FileSaveListener(mainHandler, tmpDir);
InitConfig config = getInitConfig(listener);
// 此处可以改为MySyntherizer 了解调用过程
synthesizer = new NonBlockSyntherizer(this, config, mainHandler);
if (!isOnlineSDK) {
Timber.i("SynthActivity" + "so version:" + SynthesizerTool.getEngineInfo());
}
}
Aggregations