C# TTS 文字和英文
using System;
using System.Globalization;
using System.Linq;
using System.Speech.Synthesis;
using System.Windows.Forms;
namespace TTS
{
public partial class Form1 : Form
{
private SpeechSynthesizer speech = new SpeechSynthesizer();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
#region 只能读数字和英文
//string text = textBox1.Text;
//if (text.Trim().Length != 0)
//{
// speech.Rate = 5;//语速
// speech.SelectVoice("Microsoft Lili");//设置播音员(中文)
// //speech.SelectVoice("Microsoft Anna"); //英文
// speech.Volume = 100; //音量
// speech.SpeakAsync(textBox1.Text);//语音阅读方法
//}
#endregion
#region 可以读取中文
string phrase = "龙腾至尊牛逼";
SpeechSynthesizer speech = new SpeechSynthesizer();
CultureInfo keyboardCulture = System.Windows.Forms.InputLanguage.CurrentInputLanguage.Culture;
InstalledVoice neededVoice = speech.GetInstalledVoices(keyboardCulture).FirstOrDefault();
if (neededVoice == null)
{
phrase = "Unsupported Language";
}
else if (!neededVoice.Enabled)
{
phrase = "Voice Disabled";
}
else
{
speech.SelectVoice(neededVoice.VoiceInfo.Name);
}
speech.Speak(phrase);
#endregion
}
}
}