[WindowsPhone] 隨貼即用 - 用手機唸一段文字(中文)
2013-10-22
簡述 : 讓手機念出指定文字
難度 : ★
範例敘述: 一顆按鈕,點擊後唸一段中文
程式碼:
private void btnReadText_Click(object sender, RoutedEventArgs e)
{
SpeechSynthesizer synth = new SpeechSynthesizer();
//如果需要念中文 下面兩行要加上去
IEnumerable<VoiceInformation> frenchVoices = from voice in InstalledVoices.All
where voice.Language == "zh-TW"
select voice;
synth.SetVoice(frenchVoices.ElementAt(0));
synth.SpeakTextAsync("您好,我是當麻許。");
}
注意事項:
1. 需加入 ID_CAP_SPEECH_RECOGNITION 權限
打開專案下,Properties 中 WMAppManifest.xml 點擊兩下後進入設定
選擇 Capabilities 並且將 ID_CAP_SPEECH_RECOGNITION 打勾
2.記得先引用
using using Windows.Phone.Speech.Synthesis;
參考連結:
Windows Phone 8 – Text-to-Speech (TTS)讓應用程式讀出內容
下載源碼:
標籤:
隨貼即用
,
C#
,
WindowsPhone
-- Yesterday I wrote down the code. I bet I could be your hero. I am a mighty little programmer. 如果這篇文章有幫助到您,簡單留個言,或是幫我按個讚,讓我有寫下去的動力...