您的位置:首页 > 编程语言 > C#

C# 实现Text to Speech

2009-09-02 15:35 381 查看
Windows Speech SDK 5.1 下载链接 http://www.microsoft.com/downloads/details.aspx?FamilyID=5e86ec97-40a7-453f-b0ee-6583171b4530&displaylang=en

需要下载文件:
SpeechSDK51.exe (开发包)和 SpeechSDK51LangPack.exe(语言包)

API引用



GUI设计



后台Code:

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;

namespace TTSApplication
{
public partial class Form1 : Form
{
SpeechVoiceSpeakFlags SpFlags;

SpVoice voice;

public Form1()
{
InitializeComponent();

SpFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;

voice = new SpVoice();
}

private void Speakerbutton_Click(object sender, EventArgs e)
{
string content = ContenttextBox.Text;

try
{
voice.Speak(content.Length > 0 ? content : "请输入朗读内容", SpFlags);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

private void Cancelbutton_Click(object sender, EventArgs e)
{
Dispose();

Close();
}

private void RatetrackBar_Scroll(object sender, EventArgs e)
{
voice.Rate = RatetrackBar.Value;
}

private void VolumntrackBar_Scroll(object sender, EventArgs e)
{
voice.Volume = VolumntrackBar.Value;
}
}
}

主要实现 机器朗读文本框中的内容,可以调节朗读语速和声音。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: