Hello, I am trying to use Window speech API in Unity. I copied the System.Speech.dll to the asset folder and use the code below. However, I got the following error and it seems I need to use something else to replace the event handler. Any suggestions?
“Assets/VoiceRecognition.cs(29,29): error CS0246: The type or namespace name EventHandler
1’ could not be found. Are you missing a using directive or an assembly reference?”
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Speech.AudioFormat;
using System.Speech.Recognition;
using System.Speech.Recognition.SrgsGrammar;
using System.Speech.Synthesis;
using System.Speech.Synthesis.TtsEngine;
public class VoiceRecognition : MonoBehaviour {
SpeechSynthesizer synth;
SpeechRecognitionEngine speechRecognitionEngine;
System.Timers.Timer timer;
// Use this for initialization
void Start () {
// the recognition engine
speechRecognitionEngine = new SpeechRecognitionEngine();
speechRecognitionEngine.AudioLevelUpdated +=
new EventHandler<AudioLevelUpdatedEventArgs>(engine_AudioLevelUpdated);
speechRecognitionEngine.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
speechRecognitionEngine.SpeechDetected +=
new EventHandler<SpeechDetectedEventArgs>(sre_SpeechDetected);
speechRecognitionEngine.SpeechHypothesized +=
new EventHandler<SpeechHypothesizedEventArgs>(sre_SpeechHypothesized);
speechRecognitionEngine.SpeechRecognitionRejected +=
new EventHandler<SpeechRecognitionRejectedEventArgs>(sre_SpeechRejected);
Choices colors = new Choices();
colors.Add(new string[] { "front", "back", "up", "down", "left", "right" });
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
Grammar g = new Grammar(gb);
//Grammar g = new DictationGrammar();
speechRecognitionEngine.LoadGrammar(g);
}
// Update is called once per frame
void Update () {
}
// Create a simple handler for the SpeechRecognized event.
void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
//Console.WriteLine(e.Result.Text);
//MessageBox.Show("Speech recognized: " + e.Result.Text);
Debug.Log("Speech recognized: " + e.Result.Text + "\r\n");
}
void engine_AudioLevelUpdated(object sender, AudioLevelUpdatedEventArgs e)
{
Debug.Log("Audio detected: " + e.AudioLevel + "\r\n");
}
}
Hello, I am trying to use Windows speech API in Unity. I copied the System.Speech.dll to the asset folder and below is my code.