最近跟老师用C#做一个语音识别东西,我的第一个任务是用
VS2005里面的控件webBrowser先打开一个网页.然后再用TTS把
网页里的text转换成语音读出来
大概流程就是这样了,我是不是要添加引用什么数据库啊,之前
在网上找了些些TTS的代码,但是菜鸟是不会利用他们的,My 
GOD,为什么我会菜的一塌糊涂,55,请高手指点,最好给出我想
要的详细代码,谢谢了.第一次来这里就留这么高难度的问
题.Sorry...hehe  ..thank u

解决方案 »

  1.   

    www.codeporject.com 
    里面见过这样的例子,而且他那个找回密码功能中 有这个功能
      

  2.   

    //引进Microsoft Speech Object Library 先建一个类库文件 VoiceDll
    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");
               
                //中文好象用不上 能改的给改一下
                
            }
           
        }
      
          
    }
      

  3.   

            private void Form1_Load(object sender, EventArgs e)
            {
                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);
            }
    这样可以读出网站的部分内容!但是感觉上有点乱!理想的状态我觉得是鼠标移到某部分上面,进行某部分的阅读。
      

  4.   

    webBrowser1.Document.Body.InnerText 是提取出网页文本BODY部分的文字,但是包含\r,\n然后继续剔除,这样就可以有正确的BODY,再用SPEAK读出来就好了!但是奇怪的是我提取新浪的时候只取到了部分文字!可能是和网页的做发有关系。
      

  5.   

    我把你那代码弄过来.运行了下.还是不行.
    是不是该引用哪个DLL啊.请你再看看哦.把代码完全写出来,我还没结账,好了分全给你,嘻嘻..
      

  6.   

    这是我写的代码,引用了DoNetSpeech.dll.这个DLL是我们老师给我的.这程序能运行,但是不能读出webBrowser里面的内容,请指点.告诉我代码哪有错误.正确的应该是怎么样..拜托了.谢谢.using System;
    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();
            }
        }
    }
      

  7.   

    你的代码似乎行不通.还有.那个Microsoft Speech Object Library哪里有啊..网上找不到.
    www.codeporject.com 打错了吧.呵呵.应该是www.codeproject.com 吧.不过我英文比较次,能给我找到你说的"那个找回密码功能 有这个功能"的网址吗.谢谢了.拜托
      

  8.   

    webBrowser1.Text.ToString() 是HTML代码
    使用内部的代码是在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); 
            } 
      

  9.   


    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);
            }