using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using SpeechLib; using System.Threading; namespace WindowsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags.SVSFlagsAsync; //Item(0)单词男声Sam //Item(1)单词男声Mike //Item(2)单词女声Mary //Item(3)中文发音,如果是英文,就依单词字母一个一个发音 //Speach.instance().AnalyseSpeak(txtContent.Text.Trim()); SpeechLib.SpVoiceClass voice = new SpVoiceClass(); int x; if (textBox2.Text== string.Empty) { x = 0; } else x = Convert.ToInt16(textBox2.Text); voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(x); if (textBox1.Text == string.Empty) { voice.Speak("输入内容", flag); } else voice.Speak(textBox1.Text.Trim(), flag); //本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/marvinhong/archive/2008/06/25/2586232.aspx } private void button2_Click(object sender, EventArgs e) { SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags.SVSFlagsAsync; //Item(0)单词男声Sam //Item(1)单词男声Mike //Item(2)单词女声Mary //Item(3)中文发音,如果是英文,就依单词字母一个一个发音 //Speach.instance().AnalyseSpeak(txtContent.Text.Trim()); SpVoiceClass voice=new SpVoiceClass(); int x =Convert.ToInt16( textBox2.Text); voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(x); SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite; SpFileStream SpFileStream = new SpFileStream(); string mypath=Application.StartupPath; SpFileStream.Open(mypath+@"/voice.wav", SpFileMode, false); voice.AudioOutputStream = SpFileStream;//设定voice的输出为Stream voice.Speak(textBox1.Text.Trim(), flag); voice.WaitUntilDone(Timeout.Infinite);//Using System.Threading; 添加系统的头文件system.THreeding SpFileStream.Close(); //本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/marvinhong/archive/2008/06/30/2599530.aspx } private void textBox1_TextChanged(object sender, EventArgs e) { } } } 检查字符串为空利用textbox.text==tring.empty