我只是遇到这个奇怪问题的人吗?有时它说话,有时不说话。在我开始调试后大约3-5秒,它自动执行speech ==“Hello Enzo”,没有说什么。 (没有来自背景的声音,所以我相信我是唯一一个说话的人)
有时当我说话时它不起作用我不得不一次又一次地开始调试,直到它听到并回答我。
以下是一些调试
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"); }
}
}
}
}
答案 0 :(得分:0)
快速搜索跟踪顶部的错误:“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));