坑爹的语音合成,wp8只需要下载个语言包就可以实现中文的语音合成,但android只支持几种(英文、法语、德语等几种拉丁语系)。找了几个开源的合成引擎都不是很满意,退而求其次选择语音合成服务(讯飞),实现方式:

1、将SpeechApi.jar拷到工程的libs下,

2、

private static String TAG = "TTSTest";

private SpeechSynthesizer mTts;

private Toast mToast;


@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);


// 初始化合成对象

mTts = new SpeechSynthesizer(this, mTtsInitListener);

mToast = Toast.makeText(this, "", Toast.LENGTH_LONG);


Button button = (Button) findViewById(R.id.button1);

button.setOnClickListener(new OnClickListener() {

String s = ((EditText) findViewById(R.id.editText1)).getText()

.toString();

@Override

public void onClick(View arg0) {

mTts.setParameter(SpeechConstant.ENGINE_TYPE, "cloud");

// mTts.setParameter(SpeechSynthesizer.VOICE_NAME, "vixk");

// mTts.setParameter(SpeechConstant.ENGINE_TYPE, "local");

mTts.setParameter(SpeechSynthesizer.VOICE_NAME, "xiaoyan");

mTts.setParameter(SpeechSynthesizer.SPEED, "50");

mTts.setParameter(SpeechSynthesizer.PITCH, "50");

int code = mTts.startSpeaking(s, mTtsListener);

if (code != 0) {

showTip("start speak error : " + code);

} else

showTip("start speak success.");


}

});

}

暂时选择这种办法把,但是这种有几个问题。一是语音要从服务器端传回的音频流,流量消耗比较大(wp8是本地合成),二是网络不好的情况下会比较慢。