public void SpeechRejectedCallback( ){ // announce the rejection ? // add the unrecognized clip to a list to be logged on the next successful command if (logFailures) { // log the clip as unrecognized: SpeechInputRecord newRecord = new SpeechInputRecord(); newRecord.clip = MicrophoneMgr.GetInstance ().Microphone.GetCurrentClip (); string caseName = CaseConfigurator.GetInstance().data.casename.Replace(" ",""); newRecord.filename = caseName+System.DateTime.Now.ToShortDateString () +"-"+System.DateTime.Now.ToLongTimeString(); newRecord.filename = newRecord.filename.Replace("/","-"); newRecord.filename = newRecord.filename.Replace(":","-"); newRecord.filename = newRecord.filename.Replace(" ","-"); newRecord.status = MicrophoneMgr.GetInstance ().Microphone.status.ToString (); unrecognizedClips.Add (newRecord); } VoiceMgr.ResumeSpeaking (); Brain.GetInstance ().ResumeAudioQueue (); SAPISpeechManager.Instance.expectingResult = false; SAPISpeechManager.Instance.CancelInvoke ("ExpectingResultTimeout"); // VoiceMgr.GetInstance().Play ("ProcedureResident","VOICE:BAD:COMMAND:1"); //SAPISpeechManager.Instance.PlayAudio ("BAD:COMMAND:1"); textSpoken = " --- speech rejected callback received --- "; SAPISpeechManager.Instance.micError = MicrophoneMgr.GetInstance ().Microphone.status; SAPISpeechManager.Instance.Invoke ("ClearMicError", 3); return; }
public void SpeechRecognizedCallback(string text){ // the parameter text isnt used VoiceMgr.ResumeSpeaking(); Brain.GetInstance ().ResumeAudioQueue (); SAPISpeechManager.Instance.CancelInvoke ("ExpectingResultTimeout"); SAPISpeechManager.Instance.micError = Microphone.eClipStatus.ok; // Debug.Log ("Speech Recognized " + text); if (!SAPISpeechManager.Instance.isActivated || !SAPISpeechManager.Instance.expectingResult) return; // here is where we send the semantic phrase to the dispatcher... IntPtr pPhraseTag = SAPIWrapper.GetRecognizedTag(); string commandPhrase = Marshal.PtrToStringUni(pPhraseTag); SAPISpeechManager.Instance.phraseConfidence = (int)(SAPISpeechManager.Instance.RequiredConfidence*100f); pPhraseTag = SAPIWrapper.GetSpokenText(); string spokenPhrase = Marshal.PtrToStringUni(pPhraseTag); SendPhraseToInfoDialog (spokenPhrase); if (commandPhrase.Contains ("%")){ string[] parts = commandPhrase.Split('%'); SAPISpeechManager.Instance.phraseConfidence = int.Parse(parts[0]); commandPhrase = parts[1]; } if (commandPhrase.Contains ("=")) { //Fragments understood but not a complete command VoiceMgr.GetInstance().Play ("ProcedureResident","VOICE:BAD:COMMAND:1"); //SAPISpeechManager.Instance.PlayAudio ("BAD:COMMAND:1"); SAPISpeechManager.Instance.expectingResult = false; textSpoken = " --- please rephrase your command --- "; if (logFailures) { // log the clip as unrecognized: SpeechInputRecord newRecord = new SpeechInputRecord(); newRecord.clip = MicrophoneMgr.GetInstance ().Microphone.GetCurrentClip (); string caseName = CaseConfigurator.GetInstance().data.casename.Replace(" ",""); newRecord.filename = caseName+System.DateTime.Now.ToShortDateString () +"-"+System.DateTime.Now.ToLongTimeString(); newRecord.filename = newRecord.filename.Replace("/","-"); newRecord.filename = newRecord.filename.Replace(":","-"); newRecord.filename = newRecord.filename.Replace(" ","-"); newRecord.status = MicrophoneMgr.GetInstance ().Microphone.status.ToString () + "["+commandPhrase+"]"; unrecognizedClips.Add (newRecord); } } string[] commands = commandPhrase.Split ('+'); // send off multiple commands if separated by '+' foreach (string command in commands) { if (command.Contains (":")){ StartCommand (command); // if there were any misses, log them as having been attempts at this command if (logFailures && unrecognizedClips.Count > 0) { foreach (SpeechInputRecord record in unrecognizedClips){ record.nextCommand = commandPhrase; record.filename = command.Replace (":","-")+"_"+record.status+"_"+record.filename; LogRecord(record); } unrecognizedClips.Clear(); } } } }
void LogRecord(SpeechInputRecord record){ MemoryStream memStream = SaveWav.Save (record.clip);//SaveWav.TrimSilence (currentClip, 0.1f)); string path = Application.dataPath + "/../SAPIErrors"; // get application path and create folder if doesn't exist if ( Directory.Exists(path) == false ) Directory.CreateDirectory(path); path = path + "/"; try{ FileStream file = new FileStream(path+record.filename+".wav", FileMode.Create, FileAccess.Write); memStream.WriteTo(file); file.Close(); } catch { Debug.LogError("Error opening speech error log .wav file"); } // XmlSerializer serializer = new XmlSerializer(typeof(SpeechInputRecord)); // FileStream stream = new FileStream( path+record.filename+".xml", FileMode.Create); // serializer.Serialize(stream, record); // stream.Close(); }
public void ExpectingResultTimeout(){ expectingResult = false; SAPISpeechManager.Instance.micError = MicrophoneMgr.GetInstance ().Microphone.status; SAPISpeechManager.Instance.Invoke ("ClearMicError", 3); // for debug, get any info you can from SAPI IntPtr pPhraseTag = SAPIWrapper.GetSpokenText(); string spokenText = Marshal.PtrToStringUni(pPhraseTag); pPhraseTag = SAPIWrapper.GetRecognizedTag(); string recognizedTag = Marshal.PtrToStringUni(pPhraseTag); if (logFailures) { // log the clip as unrecognized: SpeechInputRecord newRecord = new SpeechInputRecord(); newRecord.clip = MicrophoneMgr.GetInstance ().Microphone.GetCurrentClip (); string caseName = CaseConfigurator.GetInstance().data.casename.Replace(" ",""); newRecord.filename = caseName+System.DateTime.Now.ToShortDateString () +"-"+System.DateTime.Now.ToLongTimeString(); newRecord.filename = newRecord.filename.Replace("/","-"); newRecord.filename = newRecord.filename.Replace(":","-"); newRecord.filename = newRecord.filename.Replace(" ","-"); newRecord.status = MicrophoneMgr.GetInstance ().Microphone.status.ToString ()+"-processingTimedOut"; unrecognizedClips.Add (newRecord); if (!AnnounceSoundError()){ VoiceMgr.GetInstance().Play ("ProcedureResident","VOICE:BAD:COMMAND:"+(feedbackIndex+2).ToString()); // PlayAudio("BAD:COMMAND:"+ (feedbackIndex+2).ToString()); // in a very trauma specific way, have the PR give these messages: feedbackIndex = ++feedbackIndex%3; if (playbackFailures) Brain.GetInstance().QueueAudio( MicrophoneMgr.GetInstance ().Microphone.GetCurrentClip (),null); } } }