// 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> /// cTor. /// </summary> /// <param name="pfe">blank string if '!isConsole'</param> internal SapiLipsync(string pfe = "") { That = this; #if DEBUG logfile.Log(); logfile.Log("SapiLipsync() cTor pfe= " + pfe); logfile.Log(". create (SpVoice)_voice"); #endif _voice = new SpVoice(); #if DEBUG logfile.Log(". (SpVoice)_voice CREATED"); #endif _voice.Volume = 0; _voice.Rate = 10; _voice.Phoneme += tts_Phoneme; _voice.EndStream += tts_EndStream; /* * https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee125220%28v%3dvs.85%29 * enum SpeechVoiceEvents * SVEStartInputStream = 2 * SVEEndInputStream = 4 * SVEVoiceChange = 8 * SVEBookmark = 16 * SVEWordBoundary = 32 * SVEPhoneme = 64 * SVESentenceBoundary = 128 <- * SVEViseme = 256 <-- * SVEAudioLevel = 512 * SVEPrivate = 32768 * SVEAllEvents = 33790 */ _voice.EventInterests = (SpeechVoiceEvents)(int)SpeechVoiceEvents.SVEPhoneme + (int)SpeechVoiceEvents.SVEEndInputStream; #if DEBUG logfile.Log(". _voice.EventInterests= " + _voice.EventInterests); #endif #if DEBUG logfile.Log(". create (SpPhoneConverter)_phoneConverter"); #endif _phoneConverter = new SpPhoneConverter(); #if DEBUG logfile.Log(". (SpPhoneConverter)_phoneConverter CREATED"); // PrintPhons(1036); // test fr-FR #endif if (FxeGeneratorF.isConsole) { _phoneConverter.LanguageId = 1033; // EnglishUS (default) // TODO: <-- Wavefile = AudioConverter.deterwave(pfe); #if DEBUG logfile.Log(". Wavefile= " + Wavefile); #endif } }