Я работаю над программой распознавания речи на C# (с использованием Visual Basic 2013), и когда я ее компилирую и тестирую, она отлично работает для первой команды, но дает мне странное исключение, когда я говорю вторая команда. Детали:Ошибка устройства. - Код ошибки: 0x4
Первый шанс исключение типа 'System.Speech.Internal.Synthesis.AudioException' произошло в System.Speech.dll
исключение типа «System.Speech.Internal.Synthesis. AudioException "произошел в System.Speech.dll, но не был обработан в коде пользователя
Дополнительная информация: Ошибка устройства. - Код ошибки: 0x4
Мой код достаточно несколько строк длиной, но вот первый и, возможно, связано часть:
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.Recognition;
using System.Speech.Synthesis;
using System.IO;
using System.Xml;
using System.Web;
namespace JarvisTest
{
public partial class Form1 : Form
{
SpeechRecognitionEngine _recognizer = new SpeechRecognitionEngine();
SpeechSynthesizer JARVIS = new SpeechSynthesizer();
string QEvent;
string ProcWindow;
double timer = 10;
int count = 1;
Random rnd = new Random();
string Temperature;
string Condition;
string Humidity;
string WindSpeed;
string Town;
string TFCond;
string TFHigh;
string TFLow;
string Stuff;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
_recognizer.SetInputToDefaultAudioDevice();
_recognizer.LoadGrammar(new DictationGrammar());
_recognizer.LoadGrammar(new Grammar(new GrammarBuilder(new Choices(File.ReadAllLines(@"C:\Users\Aristotelis\Documents\JarvisTest.txt")))));
_recognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(_recognizer_SpeechRecognized);
_recognizer.RecognizeAsync(RecognizeMode.Multiple);
}
void _recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
int ranNum = rnd.Next(1, 10);
string speech = e.Result.Text;
switch (speech)
{
//WOLFRAM
case "ram":
WolframAlpha();
JARVIS.Speak("time for stuff" + Stuff);
break;
//WEATHER
case "hows the weather":
GetWeather();
JARVIS.Speak("The temperature in " + Town + " is " + Temperature + " degrees.");
break;
//GREETINGS
case "hello":
case "hello jarvis":
if (ranNum < 6) { JARVIS.Speak("Hello sir"); }
else if (ranNum > 5) { JARVIS.Speak("Hi"); }
break;
Я не уверен, что вызывает проблему. Любая помощь высоко оценена, спасибо заранее.
Стек трассировки показывает:
Expression: ((System.Speech.Internal.Synthesis.AudioException)$exception).StackTrace
Value:
at System.Speech.Internal.Synthesis.VoiceSynthesis.Speak(Prompt prompt)
at System.Speech.Synthesis.SpeechSynthesizer.Speak(Prompt prompt)
at System.Speech.Synthesis.SpeechSynthesizer.Speak(String textToSpeak)
at JarvisTest.Form1._recognizer_SpeechRecognized(Object sender, SpeechRecognizedEventArgs e) in c:\Users\Aristotelis\Documents\Visual Studio 2012\Projects\JarvisTest\JarvisTest\Form1.cs:line 77
at System.Speech.Recognition.SpeechRecognitionEngine.SpeechRecognizedProxy(Object sender, SpeechRecognizedEventArgs e)
Что говорит Google? –
Я действительно искал Google, когда я столкнулся с ошибкой, но не нашел никакой относительной информации - нашел только некоторые другие ошибки, такие как 0x2 и т. Д. Вот почему мне нужна помощь здесь. – user2661191
Можете ли вы получить HRESULT своего исключения? Запустите VS в режиме отладки и когда возникнет исключение, попробуйте получить HRESULT. –