C#中如何使用Speech发音 高手进

smaworm 2009-08-10 10:34:14
软件需求发音,查找了下相关资料,说是Microsoft Speech 可以做到,这方面的高手请指点迷津,在C#中如何使用,最好给点小例子,谢谢!
...全文
1082 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pprr2009 2009-08-10
  • 打赏
  • 举报
回复
CSDN有代码实现语音的 可以下来看看 但是效果不是很好 需要改动
同时 还要安装SDK5.1 和中文语音库
kkun_3yue3 2009-08-10
  • 打赏
  • 举报
回复
http://msdn2.microsoft.com/en-us/library/system.speech.synthesis.speechsynthesizer.pause.aspx

.NET 3.0 +
引用using System.Speech.Synthesis;
public static readonly SpeechSynthesizer Talker = new SpeechSynthesizer();

            Talker.Rate = -2;
Talker.Volume = 100;
Talker.SelectVoiceByHints( VoiceGender.Male, VoiceAge.Child, 2, System.Globalization.CultureInfo.CurrentCulture );


Talker.SpeakAsync("hello world");


另参见

另一种方式,使用System.Media.SoundPlayer
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Audio Files (.wav)|*.wav";

if (dialog.ShowDialog() == DialogResult.OK)
{
string path = dialog.FileName;
playSound(path);
}

}
private void playSound(string path)
{
System.Media.SoundPlayer player =
new System.Media.SoundPlayer();
player.SoundLocation = path;
player.Load();
player.Play();
}
zteclx 2009-08-10
  • 打赏
  • 举报
回复
.NET还有这个功能,不过个人觉得效果可能不好。做的好的,有中国科大做的一个系统
lazy20018 2009-08-10
  • 打赏
  • 举报
回复
//系统需要引用microsoftspeechlibobject.DLL

//此例子需要在窗口中添加一个button和一个textbox

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SpeechLib; //系统要先引用microsoftspeechlibobject.DLL文件

namespace WindowsApplication3

{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{


}

private void button1_Click(object sender, EventArgs e)
{
SpeechVoiceSpeakFlags flag = SpeechVoiceSpeakFlags.SVSFlagsAsync; //没研究明白什么含义,估计是异步发音

//Item(0)单词男声Sam

//Item(1)单词男声Mike

//Item(2)单词女声Mary

//Item(3)中文发音,如果是英文,就依单词字母一个一个发音



//Speach.instance().AnalyseSpeak(txtContent.Text.Trim());
SpeechLib.SpVoiceClass voice = new SpVoiceClass(); //定义一个语音对象,网上很多例子,没有这个对象的说明


voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(2);

// 选用的语音库编号,系统的语音库可以通过“控制面板”---“语音”来查看


voice.Speak(textBox1.Text.Trim(), flag);

//发音,需要在窗口中添加 一个button和一个textbox,利用box来输入文本

//经过试验能够连读中文和英文

//但是还有点问题,主要是语速、音调不知道如何调节




}
}
}



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lazy20018/archive/2009/08/10/4432066.aspx

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧