using System.Speech.Synthesis;
using System.IO;
调用IO库
private void btnSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(textBox1.Text))
{
MessageBox.Show("内容不可为空");
return;
}
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "mp3文件|*.mp3|wav文件|*.wav";
if (sfd.ShowDialog() == DialogResult.OK)
{
SpeechSynthesizer speech = new SpeechSynthesizer();
//speech.Rate = trackSpeed.Value;
//speech.Volume = trackVolumn.Value;
speech.SetOutputToWaveFile(sfd.FileName);
speech.Speak(textBox1.Text);
speech.SetOutputToNull();
MessageBox.Show("保存成功");
}
}