Form1.cs
资源名称:speech.rar [点击查看]
上传用户:cookies0
上传日期:2022-07-28
资源大小:284k
文件大小:2k
源码类别:
语音合成与识别
开发平台:
Visual C++
- 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 tryreco
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- SpRecognition cc = new SpRecognition();
- cc.BeginRec(textBox1);
- }
- private void button2_Click_1(object sender, EventArgs e)
- {
- SpRecognition cc = new SpRecognition();
- cc.CloseRec();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- SpVoiceClass voice = new SpVoiceClass();
- voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(3);
- voice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFDefault); ;
- }
- private void button4_Click(object sender, EventArgs e)
- {
- SpeechVoiceSpeakFlags spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
- SpVoice voice = new SpVoice();
- SaveFileDialog dialog = new SaveFileDialog();
- dialog.Filter = "All files (*.*)|*.*|wav files (*.wav)|*.wav";
- dialog.Title = "保存WAV文件";
- dialog.FilterIndex = 2;
- dialog.RestoreDirectory = true;
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- SpeechStreamFileMode spFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
- SpFileStream spFileStream = new SpFileStream();
- spFileStream.Open(dialog.FileName, spFileMode, false);
- voice.AudioOutputStream = spFileStream;
- voice.Speak(textBox1.Text, spFlags);
- voice.WaitUntilDone(1000);
- //上面两句一定要写上,否则产生的文件没有声音
- //WaitUntilDone的后面的smTimeout是一个int型
- spFileStream.Close();
- }
- }
- }
- }