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();

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

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
}
}
}

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄