//private SpeechRecognizer speech = new SpeechRecognizer(); public MainWindow() { InitializeComponent(); //1 /* * SpeechSynthesizer synthesizer = new SpeechSynthesizer(); * synthesizer.Speak("Hello,world.my name is ok baba"); */ //2 /* * PromptBuilder prompt = new PromptBuilder(); * prompt.AppendText("Hello,world.my name is ok baba"); * SpeechSynthesizer synthesizer = new SpeechSynthesizer(); * synthesizer.Speak(prompt); */ /* * speech.SpeechDetected += Speech_SpeechDetected; * speech.SpeechHypothesized += Speech_SpeechHypothesized; * speech.SpeechRecognized += Speech_SpeechRecognized; * speech.SpeechRecognitionRejected += Speech_SpeechRecognitionRejected; * button1.Focus(); //按钮获取输入焦点 * */ SRE.SetInputToDefaultAudioDevice(); GrammarBuilder GB = new GrammarBuilder(); GB.Append("选择"); GB.Append(new Choices(new string[] { "红色", "绿色" })); Grammar G = new Grammar(GB); G.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(G_SpeechRecognized); SRE.LoadGrammar(G); SRE.RecognizeAsync(RecognizeMode.Multiple); }
public void StartRecognizing() { SRE.RecognizeAsync(RecognizeMode.Multiple); }
public void StopRecognizing() { SRE.RecognizeAsyncStop(); }
// Update is called once per frame void Update() { if (gamestarted) { if (currentSpeakerIndex >= speakerOrder.Count) { Debug.Log("Update: index at done: " + currentSpeakerIndex); // Create start mission Menu Debug.Log("Update: done"); GameManager.gameManager.DoneWithDialogScene(0); } else { string currentSpeakerName = speakerOrder [currentSpeakerIndex]; // If someone is speaking, check if they're done if (isPlaying) { if (currentSpeakerName == "Player") { isPlaying = GameObject.Find(currentSpeakerName).GetComponent <SRE> ().isActive(); //isPlaying = GameObject.Find (currentSpeakerName).GetComponent<SREPhrase> ().isActive (); } else { isPlaying = GameObject.Find("/Characters/" + speakerOrder [currentSpeakerIndex]).GetComponent <Dialog> ().isActive(); if (!isPlaying && currentSpeakerName == "Response") { GameManager.gameManager.UnloadPhrase(phraseNum); phraseNum++; } } if (!isPlaying) { Debug.Log("update: is not playing: " + currentSpeakerIndex); currentSpeakerIndex += 1; } //Debug.Log (currentSpeakerIndex + "is playing"); } // if current is done, start the next one else if (!isPlaying && (currentSpeakerIndex < speakerOrder.Count)) { Debug.Log("update: currrent speaker index: " + currentSpeakerIndex); if (currentSpeakerName == "Player") { Debug.Log("update: is player"); SRE playerSRE = GameObject.Find("Player").GetComponent <SRE> (); //SREPhrase playerSRE = GameObject.Find ("Player").GetComponent<SREPhrase> (); //Update phrase prompt //GameManager.gameManager.LoadNextPhrase(phraseNum); playerSRE.LoadNextPhrase(phraseNum); Debug.Log("loading phrase"); playerSRE.Begin(); isPlaying = true; } else { Dialog speakerDia = GameObject.Find("/Characters/" + speakerOrder [currentSpeakerIndex]).GetComponent <Dialog> (); speakerDia.PlayNext(); //Debug.Log ("got speaker"); isPlaying = true; Debug.Log(currentSpeakerIndex + " started-Update"); } if (currentSpeakerName == "Pre") { GameManager.gameManager.LoadNextPhrase(phraseNum); } } } } }