先在C盘下找到sapi.dll文件,添加的引用
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SpeechLib;
namespace WindowsApplication1
...{
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
...{
try
...{
SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice voice = new SpVoice();
if (this.richTextBox1.Text.Trim() == string.Empty)
...{
voice.Speak("请输入数据!", spFlags);
}
else
...{
voice.Speak(this.richTextBox1.Text, spFlags);
}
}
catch (Exception Err)
...{
MessageBox.Show(Err.Message);
}
}
}
}
1692





