一个有趣的东西,今后可能用得上。
C#语音识别:在命名空间 System.Speech下SpeechSynthesizer可以将文字转换成语音
贴出代码:
public partial class Form1 : Form { private SpeechSynthesizer ss; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { ss = new SpeechSynthesizer(); } private void button1_Click(object sender, EventArgs e) { ss.Rate = trackbarSpeed.Value; ss.Volume = trackbarVoice.Value; ss.SpeakAsync(txtSpeechText.Text); } private void button2_Click(object sender, EventArgs e) { ss.Pause(); } private void button3_Click(object sender, EventArgs e) { ss.Resume(); } private void button4_Click(object sender, EventArgs e) { SpeechSynthesizer ss = new SpeechSynthesizer(); ss.Rate = trackbarSpeed.Value; ss.Volume = trackbarVoice.Value; SaveFileDialog savefd = new SaveFileDialog(); savefd.Filter = "wave Files|*.wav"; ss.SetOutputToWaveFile(savefd.FileName); ss.Speak(txtSpeechText.Text); ss.SetOutputToDefaultAudioDevice(); MessageBox.Show("完成录音~~~", "提示"); } private void button5_Click(object sender, EventArgs e) { Application.Exit(); } }
时间: 2024-11-05 15:48:54