语音识别不起作用 [英] Speech recognition not working

查看:118
本文介绍了语音识别不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Synthesis;
using System.Speech.Recognition;

namespace Alice
{
    public partial class Form1 : Form
    {

        SpeechSynthesizer s = new SpeechSynthesizer();
        Choices list = new Choices();

        public Form1()
        {
            SpeechRecognitionEngine rec = new SpeechRecognitionEngine();
            list.Add(new String[] { "hello", "how are you" });

            s.Speak("hello, my name is Alice");
            s.SelectVoiceByHints(VoiceGender.Female);

            Grammar gr = new Grammar(new GrammarBuilder (list));

            try
            {
                rec.RequestRecognizerUpdate();
                rec.LoadGrammar(gr);
                rec.SpeechRecognized += rec_SpeechRecognized;
                rec.SetInputToDefaultAudioDevice();
                rec.RecognizeAsync(RecognizeMode.Multiple);
            }
            catch { return; }

            InitializeComponent();
        }

        public void say(String h)
        {
            s.Speak(h);
        }

        private void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            String r = e.Result.Text;

            if (r == "hello")
            {
                say("hi");
            }

            if (r == "how are you")
            {
                say("good, thanks. how about you ?");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}


您好,我在语音识别方面遵循了一个教程(很多人都有这个问题,但没有人解决它),但当我开始并说" ;你好"一切都没有发生。哪里可以问题?我的麦克风打开了。

Hello, I followed a tutorial (a lot of people have this issue, but no one solved it) on speech recognition, but when I start it and say "hello" nothing is happening. Where can be the problem ? My mic is on.

推荐答案

你好Jacob Lth,

Hi Jacob Lth,

我看到你已经初始化了这个  SpeechRecognitionEngine对象在窗体初始化之前。你试过把它放在窗体的加载事件处理程序中吗?

I saw that you have initialized that SpeechRecognitionEngine object before the window form initialized. Have you tried put that in load event handler of window form?

我在我这边测试这个样本,效果很好。您可以参考此示例来检查您的代码:  http://www.codeproject.com/Articles/483347/Speech-recognition-speech-to-text-text-to-speech-a  

I test this sample on my side, it worked well. You could refer to this sample to check your code: http://www.codeproject.com/Articles/483347/Speech-recognition-speech-to-text-text-to-speech-a 

Best此致,

Xavier Eoro

Xavier Eoro

注意:此回复包含对第三方万维网站点的引用。 Microsoft提供此信息是为了方便您。 Microsoft不控制这些网站,也未测试在这些网站上找到的任何软件或信息;因此,
Microsoft不能就其中发现的任何软件或信息的质量,安全性或适用性做出任何陈述。使用互联网上的任何软件都存在固有的危险,微软提醒您在从互联网上检索任何软件之前,确保您完全了解风险。

Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


这篇关于语音识别不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆