【发布时间】: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