C#使用微软TTS语音引擎实现文字转语音示例

转载:http://www.mzwu.com/article.asp?id=3845
在VS2012创建Windows窗体应用程序项目,添加引用COM组件Microsoft Speech Object Library:



TTS除了可以用于文字转语音,还可以将语音保存成文件,代码如下:

复制内容到剪贴板程序代码

using System;
using System.Threading;
using System.Windows.Forms;
using SpeechLib;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void btnSpeak_Click(object sender, EventArgs e)
        {
            SpVoice voice = new SpVoice();
            voice.Rate = -5; //语速,[-10,10]
            voice.Volume = 100; //音量,[0,100]
            voice.Voice = voice.GetVoices().Item(0); //语音库
            voice.Speak("木子屋网址:www.mzwu.com");
        }

        private void btnSave_Click(object sender, EventArgs e)
        {            
            SpFileStream stream = new SpFileStream();
            stream.Open(@"F:\voice.wav", SpeechStreamFileMode.SSFMCreateForWrite, false);
            SpVoice voice = new SpVoice();
            voice.AudioOutputStream = stream;
            voice.Speak("0,1,2,3,4,5,6,7,8,9");
            voice.WaitUntilDone(Timeout.Infinite);
            stream.Close();
            MessageBox.Show("ok");
        }
    }
}


Windows7 TTS语音引擎默认语音修改示例





参考资料

[1].visual c#怎么使用tts:http://zhidao.baidu.com/question/93308685.html
[2].c#之TTS发音程序:http://blog.csdn.net/kkfdsa132/article/details/5394700
[3].关于Microsoft Speech SDK 中TTS的研究 [转]:http://www.cnblogs.com/lxinxuan/archive/2007/03/17/678606.html
[4].Speech两种使用方法:http://www.cnblogs.com/MaxIE/p/3159994.html
[5].微软TTS语音引擎编程入门:http://www.jizhuomi.com/software/135.html
[6].SpVoice Interface (SAPI 5.4):http://msdn.microsoft.com/en-us/library/ee125640.aspx 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页