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,該方法也可以什麼都不做。