离线授权成功,但是只有在有网络的情况下才能合成语音,没有网络的时候合成不成功,
啥原因?
this.mSpeechSynthesizer = SpeechSynthesizer.getInstance();
this.mSpeechSynthesizer.setContext(mContext);
// 文本模型文件路径 (离线引擎使用)
this.mSpeechSynthesizer.setParam(
SpeechSynthesizer.PARAM_TTS_TEXT_MODEL_FILE, mSampleDirPath
+ "/" + TEXT_MODEL_NAME);
this.mSpeechSynthesizer.setParam(
SpeechSynthesizer.PARAM_VOCODER_OPTIM_LEVEL, "2");
this.mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_PITCH, "6");
// 声学模型文件路径 (离线引擎使用)
if (TextUtils.equals(type, SpeechSynthesizer.SPEAKER_FEMALE)) {
this.mSpeechSynthesizer.setParam(
SpeechSynthesizer.PARAM_TTS_SPEECH_MODEL_FILE,
mSampleDirPath + "/" + SPEECH_FEMALE_MODEL_NAME);
} else {
this.mSpeechSynthesizer.setParam(
SpeechSynthesizer.PARAM_TTS_SPEECH_MODEL_FILE,
mSampleDirPath + "/" + SPEECH_MALE_MODEL_NAME);
}
// 请替换为语音开发者平台上注册应用得到的App ID (离线授权)
this.mSpeechSynthesizer.setAppId(APP_ID);
// 请替换为语音开发者平台注册应用得到的apikey和secretkey (在线授权)
this.mSpeechSynthesizer.setApiKey(API_KEY, SECRET_KEY);
this.mSpeechSynthesizer.setAudioStreamType(AudioManager.STREAM_MUSIC);
// 授权检测接口
AuthInfo authInfo = this.mSpeechSynthesizer.auth(TtsMode.MIX);
if (authInfo.isSuccess()) {
this.mSpeechSynthesizer.setParam(SpeechSynthesizer.PARAM_SPEAKER,
type);
mSpeechSynthesizer.initTts(TtsMode.MIX);
System.out.println("author yuyin success");
} else {
String errorMsg = authInfo.getTtsError().getDetailMessage();
System.err.println("author yuyin error " + errorMsg);
}
1、离线设置需要正确设置appid,将appid替换成自己应用的appid
2、第一次需要联网下载授权文件,之后才能使用离线合成。
请对照官网给出的Demo例子和详细使用文档检查离线设置是否都设置正确。