Form1.cs
上传用户:cookies0
上传日期:2022-07-28
资源大小:284k
文件大小:2k
源码类别:

语音合成与识别

开发平台:

Visual C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using SpeechLib;
  9. namespace tryreco
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.         private void Form1_Load(object sender, EventArgs e)
  18.         {
  19.         }
  20.         private void button1_Click(object sender, EventArgs e)
  21.         {
  22.             SpRecognition cc = new SpRecognition();
  23.             cc.MessageBegin();
  24.             cc.BeginRec(textBox1); //Fan:把内容输入textbox1
  25.         }
  26.         private void button2_Click_1(object sender, EventArgs e)
  27.         {
  28.             SpRecognition cc = new SpRecognition();
  29.             cc.MessageEnd();
  30.             cc.CloseRec();
  31.         }
  32.         private void button3_Click(object sender, EventArgs e)
  33.         {
  34.             SpVoiceClass voice = new SpVoiceClass();
  35.             voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(3);
  36.             voice.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFDefault); ;
  37.         }
  38.         private void button4_Click(object sender, EventArgs e) //把语音转化成 .wav格式
  39.         {
  40.             //Declare the SpVoice object. 
  41.             ISpeechVoice v = new SpVoiceClass();
  42.             //Create a wave stream
  43.             SpFileStream s = new SpFileStream();
  44.             //Create a new .wav file for writing.
  45.             s.Open("out.wav", SpeechStreamFileMode.SSFMCreateForWrite, false);
  46.             //Set the .wav file stream as the output for the Voice object
  47.             v.AudioOutputStream = s;
  48.             //Call the Speak method now will send the output to the .wav file.
  49.             v.Speak(textBox1.Text, SpeechVoiceSpeakFlags.SVSFDefault);
  50.             //Close the file
  51.             s.Close();
  52.         }
  53.         private void button5_Click(object sender, EventArgs e)
  54.         {
  55.              Speach Hunhe = new Speach();
  56.            Hunhe.AnalyseSpeak(textBox1.Text);      
  57.         }
  58.     }
  59. }