// Function for extracting SAPI phonemes from voice recognition results public void GetPhonemes(ISpeechRecoResult Result) { //VA.WriteToLog("Extracting phonemes from voice recognition result"); // Output info to event log try // Attempt the following code { SpPhoneConverter MyPhoneConverter = new SpPhoneConverter(); // Create new SPPhoneConverter instance MyPhoneConverter.LanguageId = 1033; // Set the phone converter's language (English = 1033) string SAPIPhonemesRaw = null; // Initialize string for storing raw SAPI phoneme data string SAPIPhonemes = null; // Initialize string for storing delimited SAPI phoneme data int i = 1; // Initialize integer for tracking phoneme count string WordSeparator = " "; // Initialize string variable for storing the characters used to separate words within the phoneme result if (VA.GetBoolean("~~SeparatePhonemes") == true) // Check if user wants to have the "-" character separate the words within the phoneme result { WordSeparator = " - "; // Redefine the WordSeparator } foreach (ISpeechPhraseElement MyPhrase in Result.PhraseInfo.Elements) // Loop through each element of the recognized text { if (MyPhrase.DisplayText != " ") { SAPIPhonemesRaw += " " + MyPhoneConverter.IdToPhone(MyPhrase.Pronunciation); // Build string of SAPI phonemes extracted from the recognized text SAPIPhonemes += (i++ > 1 ? WordSeparator : " ") + MyPhoneConverter.IdToPhone(MyPhrase.Pronunciation); // Build string of SAPI phonemes extracted from the recognized text, delimited by " " } } MyPhoneConverter = null; // Set to null in preparation for garbage collection VA.SetText("~~SAPIPhonemesRaw", SAPIPhonemesRaw.Trim()); // Send raw SAPI phoneme data back to VoiceAttack as text variable VA.SetText("~~SAPIPhonemes", SAPIPhonemes.Trim()); // Send word-delimited SAPI phoneme data back to VoiceAttack as text variable } catch // Handle exceptions in above code { VA.SetText("~~RecognitionError", "Error during phoneme extraction"); // Send error detail back to VoiceAttack as text variable } }
/// <summary> /// Handles the TTS-stream of a typed-text. Adds its phonemes to the /// 'Expected' list. /// </summary> /// <param name="StreamNumber"></param> /// <param name="StreamPosition"></param> /// <param name="Duration"></param> /// <param name="NextPhoneId"></param> /// <param name="Feature"></param> /// <param name="CurrentPhoneId"></param> void tts_Phoneme(int StreamNumber, object StreamPosition, int Duration, short NextPhoneId, SpeechVisemeFeature Feature, short CurrentPhoneId) { #if DEBUG string ttsinfo = "tts_Phoneme() #" + StreamNumber + " StreamPosition= " + StreamPosition + " PhoneId= " + CurrentPhoneId; #endif if (CurrentPhoneId > 9) // NOTE: This causes signifiers like silence #7 "_" and nasalvowel #9 "~" to bypass. { string phon = _phoneConverter.IdToPhone(CurrentPhoneId); #if DEBUG logfile.Log(ttsinfo + " - " + phon); logfile.Log(". ADD to Expected"); #endif Expected.Add(phon); } #if DEBUG else { logfile.Log(ttsinfo + " - " + _phoneConverter.IdToPhone(CurrentPhoneId)); logfile.Log(". BYPASS Expected"); } logfile.Log(". Duration= " + Duration); logfile.Log(". Feature= " + Feature); logfile.Log(". NextPhoneId= " + NextPhoneId); logfile.Log(". nextphone= " + _phoneConverter.IdToPhone(NextPhoneId)); // iffy. Can fail silently. #endif }