私は C# で (Visual Basic 2013 を使用して) 音声認識プログラムに取り組んでいます。コンパイルして試してみると、最初のコマンドでは問題なく動作しますが、2 番目のコマンドを話すと奇妙な例外が発生します。詳細:
タイプ '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)