Android系统默认支持TTS,使用pico语音引擎,但是该引擎不支持中文。
1、使用默认语音引擎
设置->系统->辅助功能->文字转语音(TTS)输出,可以设置默认语音引擎,像m2中就装了语音助手(科大讯飞提供),支持中文发音
我们也可以自己去装一些支持中文发音的语音引擎(只要语音引擎支持中文,不需要修改代码就可以进行中文发音)
示例:
[Activity(Label = "AndroidTTS", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity,Android.Speech.Tts.TextToSpeech.IOnInitListener
{
TextToSpeech tts;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.MyButton);
tts = new TextToSpeech(this, this);
button.Click += new EventHandler(button_Click);
}
void button_Click(object sender, EventArgs e)
{
OperationResult result = tts.Speak("花开花落", QueueMode.Add, null);
}
public void OnInit(OperationResult status)
{
if (status == OperationResult.Success)
{
tts.SetLanguage(Java.Util.Locale.SimplifiedChinese);
}
}
}
需要实现IOnInitListener,并实现方法OnInit,该方法也可以什么都不做。