最近跟老师用C#做一个语音识别东西,我的第一个任务是用
VS2005里面的控件webBrowser先打开一个网页.然后再用TTS把
网页里的text转换成语音读出来
大概流程就是这样了,我是不是要添加引用什么数据库啊,之前
在网上找了些些TTS的代码,但是菜鸟是不会利用他们的,My
GOD,为什么我会菜的一塌糊涂,55,请高手指点,最好给出我想
要的详细代码,谢谢了.第一次来这里就留这么高难度的问
题.Sorry...hehe ..thank u
VS2005里面的控件webBrowser先打开一个网页.然后再用TTS把
网页里的text转换成语音读出来
大概流程就是这样了,我是不是要添加引用什么数据库啊,之前
在网上找了些些TTS的代码,但是菜鸟是不会利用他们的,My
GOD,为什么我会菜的一塌糊涂,55,请高手指点,最好给出我想
要的详细代码,谢谢了.第一次来这里就留这么高难度的问
题.Sorry...hehe ..thank u
里面见过这样的例子,而且他那个找回密码功能中 有这个功能
namespace VoiceDll
{
public class Speach
{
private static Speach _Instance = null;
private SpeechLib.SpVoiceClass voice = null; public Speach()
{
BuildSpeach();
}
private void BuildSpeach()
{
if (voice == null) voice = new SpeechLib.SpVoiceClass();
} public void Speak(string strSpeak)
{
try
{
voice.Speak(strSpeak, SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync);
}
catch (Exception err)
{
throw(new Exception("Error:"+err.Message));
} } public void SetChinaVoice()
{
voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0);
}
public void SpeakChinese(string strSpeak)
{
SetChinaVoice();
Speak(strSpeak);
} }
}
//再工程文件里面调用该类库文件
namespace SpeakTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
VoiceDll.Speach s = new VoiceDll.Speach();
s.Speak("nihao");
//中文好象用不上 能改的给改一下
}
}
}
{
Uri ur = new Uri("http://www.sina.com.cn/");
webBrowser1.Url = ur;
} private void button1_Click(object sender, EventArgs e)
{
SpeechVoiceSpeakFlags fla = SpeechVoiceSpeakFlags.SVSFlagsAsync;
SpVoice voice = new SpVoice();
string str = webBrowser1.Document.Body.InnerText.Replace("\r","").Replace("\n","");
voice.Speak(str, fla);
}
这样可以读出网站的部分内容!但是感觉上有点乱!理想的状态我觉得是鼠标移到某部分上面,进行某部分的阅读。
是不是该引用哪个DLL啊.请你再看看哦.把代码完全写出来,我还没结账,好了分全给你,嘻嘻..
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DoNetSpeech;namespace voice
{
public partial class Form1 : Form
{
public static int Speakvoice;
SpeechVoiceSpeakFlags spFlags;
SpVoice voice;
public Form1()
{
InitializeComponent();
Speakvoice = 0;
spFlags = SpeechVoiceSpeakFlags.SVSFlagsAsync;
voice = new SpVoice();
voice.Voice = voice.GetVoices("", "").Item(0);
voice.Volume = 50;
voice.Rate = 5;
}
private void BackgroundProcess()
{
voice.Speak(string.Empty, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
voice.Volume = 50;
voice.Rate = 5;
voice.Voice = voice.GetVoices("", "").Item(0);
voice.Speak(webBrowser1.Text.ToString(), spFlags);
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(textBox1.Text.ToString());
} private void button2_Click(object sender, EventArgs e)
{
BackgroundProcess();
}
}
}
www.codeporject.com 打错了吧.呵呵.应该是www.codeproject.com 吧.不过我英文比较次,能给我找到你说的"那个找回密码功能 有这个功能"的网址吗.谢谢了.拜托
使用内部的代码是在BODY里面,再过滤掉\N \R就是真实的文本代码!我觉得你错在这里!
private void BackgroundProcess()
{
voice.Speak(string.Empty, SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
voice.Volume = 50;
voice.Rate = 5;
voice.Voice = voice.GetVoices("", "").Item(0);
voice.Speak(webBrowser1.Text.ToString(), spFlags);
}
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;//添加com 控件
using System.Threading;//这个引用是用来保存语音文件用的线程类namespace windowsyy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
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(2);
//Item(0)单词男声Sam
//Item(1)单词男声Mike
//Item(2)单词女声Mary
//Item(3)中文发音,若是是英文,就依单词字母一个一个发音
voice.Speak("测试abcd语言", flag);
}