语音提示(.net平台下源码)

1. 第三方

   1-1 Interop.SpeechLib.dll

2 源码 如下

2-1 空间引用

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SpeechLib;
using System.Threading;//这个引用是用来保存语音文件用的线程类


2-2 读文字(语音提示)

 /// 
        /// 读取文字
        /// 
        /// 
        /// 
        private void button1_Click(object sender, EventArgs e)
        {
            SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice voice = new SpVoice();
            voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(3);
            //Item(0)单词男声Sam
            //Item(1)单词男声Mike
            //Item(2)单词女声Mary
            //Item(3)中文发音,若是是英文,就依单词字母一个一个发音
            voice.Speak("查询完毕!", flag);
        }


2-3 保存提示语音到xx路径

 private void button2_Click(object sender, EventArgs e)
        {
            SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpVoice voice = new SpVoice();
            voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(3);


            SpeechStreamFileMode SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
            SpFileStream SpFileStream = new SpFileStream();
            SpFileStream.Open(@"C:\test.wav",SpFileMode, false);
            voice.AudioOutputStream = SpFileStream;//设定voice的输出为Stream
            voice.Speak(textBox1.Text.Trim(),flag);
            voice.WaitUntilDone(Timeout.Infinite);//Using System.Threading;
            SpFileStream.Close();
        }



 

你可能感兴趣的:(WinForms,vs2008,.net,平台,button,textbox,object,stream)