【问题标题】:speech recognition (sometimes speaking, sometimes not)语音识别(有时说话,有时不说话)
【发布时间】:2015-08-25 18:33:38
【问题描述】:

只有我遇到了这个奇怪的问题吗?有时它会说话,有时它不会。在我开始调试它大约 3-5 秒后,它会自动执行语音 == "Hello Enzo" 而没有说任何话。 (没有背景声音,所以我确定只有我在说话)

有时当我说它不起作用时,我不得不一次又一次地开始调试它,直到它听到并回答我。

下面是一些debug

JARVIS.vshost.exe Information: 0 : SAPI does not implement phonetic alphabet selection.
The thread 0x87b0 has exited with code 0 (0x0). <<---This is the Its Good to see you again sir
The thread 0x7aec has exited with code 0 (0x0). <<---THIS is the Hello Enzo reply without speaking or saying anything
The thread 0x9544 has exited with code 0 (0x0). <<--This is Yes Good evening
The thread 0x749c has exited with code 0 (0x0). <<--This is Yes Good evening I only said. 1 "Hello Enzo" But it speak 2 times
The thread 0x8638 has exited with code 259 (0x103). <<---Randomly spam
The thread 0x57c has exited with code 259 (0x103).  <<---Randomly spam
The thread 0x91bc has exited with code 259 (0x103)  .<<---Randomly spam
The thread 0x70c8 has exited with code 259 (0x103).  <<---Randomly spam
The thread 0x907c has exited with code 259 (0x103).  <<---Randomly spam
The thread 0x8c40 has exited with code 259 (0x103).  <<---Randomly spam

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 System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Threading;
using System.Diagnostics;
using System.Web;


namespace JARVISV2
{

    public partial class Form1 : Form
    {

        SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
        SpeechSynthesizer ENZO = new SpeechSynthesizer();

        DateTime now = DateTime.Now;
        Random rnd = new Random();

        string QEvent;

        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            _recognizer.SetInputToDefaultAudioDevice();
            _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(System.IO.File.ReadAllLines(@"C:\Commands.txt")))));
            _recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
            _recognizer.RecognizeAsync(RecognizeMode.Multiple);

            ENZO.Speak("Its Good to see you again sir");

            ENZO.Rate = -1;
            ENZO.Volume = 100;
        }


        void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            int ranNum = rnd.Next(1, 10);
            string time = now.GetDateTimeFormats('t')[0];
            string speech = e.Result.Text;
            {
                if (speech == "Hello Enzo")
                {
                    if (ranNum > 6) { ENZO.SpeakAsync("How may I help you"); }
                    else if (ranNum < 5) { ENZO.SpeakAsync("Im here sir"); }
                    else if (ranNum < 7) { ENZO.SpeakAsync("Welcome back sir"); }
                    else if (ranNum < 8) { ENZO.SpeakAsync("Need assistance?"); }
                    else if (ranNum < 10) { ENZO.SpeakAsync("Whats up"); }
                }
            }
       }
}

【问题讨论】:

    标签: c# speech-recognition voice-recognition speech-synthesis


    【解决方案1】:

    快速搜索跟踪顶部的错误:“SAPI 未实现拼音字母选择”显示一些人有类似问题。

    尝试为您的 GrammarBuilder 设置文化,而不是这样:

    _recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(System.IO.File.ReadAllLines(@"C:\Commands.txt")))));
    

    试试这个:

    GrammarBuilder gb = new GrammarBuilder(new Choices(System.IO.File.ReadAllLines(@"C:\Commands.txt")));
                gb.Culture = new CultureInfo("en-US");
                _recognizer.LoadGrammar(new Grammar(gb));
    

    【讨论】:

    • 感谢您的帮助。我试过了,但它仍然显示“SAPI 没有实现拼音字母选择”我在 Form1_Load 中写了它
    • 您能否在 Windows 中运行语音识别,并让它识别您的输入?您应该可以通过 Windows 键运行它并搜索“语音”
    • 是的,它肯定能认出我的声音。我试着去控制面板讲话。它可能在代码的某个地方,但我不知道确切的位置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    相关资源
    最近更新 更多