0
請看看在跟隨着代碼如何將電腦語音加載到語音識別器中?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;
using System.Speech.Synthesis;
using System.Windows.Forms;
namespace US_Speech_Recognizer
{
public class RecognizeSpeech
{
private SpeechRecognitionEngine sEngine; //Speech recognition engine
private SpeechSynthesizer sSpeak; //Speech synthesizer
public RecognizeSpeech()
{
//Make the recognizer ready
sEngine = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US"));
//Load grammar
Choices sentences = new Choices();
sentences.Add(new string[] { "I am hungry" });
GrammarBuilder gBuilder = new GrammarBuilder(sentences);
Grammar g = new Grammar(gBuilder);
sEngine.LoadGrammar(g);
//Add a handler
sEngine.SpeechRecognized +=new EventHandler<SpeechRecognizedEventArgs>(sEngine_SpeechRecognized);
//Ask the to speak
sSpeak = new SpeechSynthesizer();
sSpeak.Rate = -2;
sSpeak.Speak("Please speak the sentence above");
//Configure the recognizer to Mike
sEngine.SetInputToDefaultAudioDevice();
sEngine.RecognizeAsync(RecognizeMode.Multiple);
}
//Start the speech recognition task
private void sEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
MessageBox.Show(e.Result.Confidence.ToString());
}
}
}
在這裏,我從麥克輸入加載。但是,而不是那個,我需要從計算機在sSpeak.Speak("Please speak the sentence above");
內部發言中加載輸入。我怎樣才能加載這個計算機語音作爲語音識別器的輸入?請幫忙。