Example #1
0
        internal void UpdateLexicons(List <LexiconEntry> lexicons)
        {
            // Remove the lexicons that are defined in this voice but are not in the list
            for (int i = _lexicons.Count - 1; i >= 0; i--)
            {
                LexiconEntry entry = _lexicons[i];
                if (!lexicons.Contains(entry))
                {
                    // Remove the entry first, just in case the RemoveLexicon throws
                    _lexicons.RemoveAt(i);
                    TtsEngine.RemoveLexicon(entry._uri);
                }
            }

            // Add the lexicons that are defined in this voice but are not in the list
            foreach (LexiconEntry entry in lexicons)
            {
                if (!_lexicons.Contains(entry))
                {
                    // Remove the entry first, just in case the RemoveLexicon throws
                    TtsEngine.AddLexicon(entry._uri, entry._mediaType);
                    _lexicons.Add(entry);
                }
            }
        }
Example #2
0
 public void Speak(string text, dynamic playDevice, bool isSync = false, float?volume = null)
 {
     try
     {
         TtsEngine?.Speak(text, playDevice, isSync, volume);
     }
     catch (Exception ex)
     {
         Controller.NotifyLogMessageAppend(false, ex.ToString());
     }
 }
Example #3
0
 public void Speak(string text, dynamic playDevice)
 {
     try
     {
         TtsEngine?.Speak(text, playDevice);
     }
     catch (Exception ex)
     {
         Controller.NotifyLogMessageAppend(false, ex.ToString());
     }
 }
Example #4
0
 public void Speak(string text)
 {
     Logger.Info($"Speak {text}");
     try
     {
         var processed = PreProcessor.Process(text);
         TtsEngine?.Speak(processed);
     }
     catch (Exception ex)
     {
         Logger.Error($"Failed to speak \"{text}\"", ex);
     }
 }
        /// <summary>
        /// Update PartOfSpeech.
        /// </summary>
        /// <param name="utt">Tts utterance.</param>
        /// <param name="scriptSentence">Script sentence.</param>
        /// <param name="engine">Tts engine.</param>
        private static void UpdatePartOfSpeech(SP.TtsUtterance utt, ScriptSentence scriptSentence, TtsEngine engine)
        {
            int wordCount = 0;

            System.Console.WriteLine("warning: update the PartOfSpeech!");
            foreach (TtsWord uttWord in utt.Words)
            {
                if (uttWord.TextLength > 0)
                {
                    uint posId = engine.PosTable.StringToId(scriptSentence.Words[wordCount].PosString);
                    uttWord.Pos = (ushort)posId;
                    wordCount++;
                }
            }
        }
        /// <summary>
        /// Update pronunciation.
        /// </summary>
        /// <param name="utt">Tts utterance.</param>
        /// <param name="scriptSentence">Script sentence.</param>
        /// <param name="engine">Tts engine.</param>
        private static void UpdatePronunciation(SP.TtsUtterance utt, ScriptSentence scriptSentence, TtsEngine engine)
        {
            int wordCount = 0;

            System.Console.WriteLine("warning: update the Pronunciation!");
            foreach (TtsWord uttWord in utt.Words)
            {
                if (uttWord.TextLength > 0)
                {
                    if (!string.IsNullOrEmpty(scriptSentence.Words[wordCount].Pronunciation) &&
                        !uttWord.Pronunciation.Equals(Offline.Core.Pronunciation.RemoveUnitBoundary(
                        scriptSentence.Words[wordCount].Pronunciation).ToUpper(CultureInfo.InvariantCulture)))
                    {
                        uttWord.PhoneIds = engine.Phoneme.PronunciationToPhoneIds(
                            Offline.Core.Pronunciation.RemoveUnitBoundary(scriptSentence.Words[wordCount].Pronunciation));
                    }

                    wordCount++;
                }
            }
        }
        /// <summary>
        /// Update silence words.
        /// </summary>
        /// <param name="utt">Engine TtsUtterance.</param>
        /// <param name="scriptSentence">Script sentence.</param>
        /// <param name="engine">Tts engine.</param>
        /// <param name="logger">Log writer object.</param>
        private static void UpdateSilenceWords(SP.TtsUtterance utt, ScriptSentence scriptSentence,
            TtsEngine engine, TextLogger logger)
        {
            // Gets phone set.
            TtsPhoneSet phoneSet = null;
            if (scriptSentence.ScriptItem != null && scriptSentence.ScriptItem.ScriptFile != null)
            {
                phoneSet = scriptSentence.ScriptItem.ScriptFile.PhoneSet;
            }

            if (phoneSet == null)
            {
                phoneSet = Localor.GetPhoneSet(scriptSentence.Language);
            }

            if (scriptSentence.ScriptItem != null && scriptSentence.ScriptItem.ScriptFile != null)
            {
                scriptSentence.ScriptItem.ScriptFile.PhoneSet = phoneSet;
            }

            int extWordIndex = 0;
            if (scriptSentence.Words[extWordIndex].WordType == WordType.Silence &&
                utt.Words[0].WordType != TtsWordType.WT_SILENCE)
            {
                string phone = scriptSentence.Words[extWordIndex].GetPronunciation(phoneSet);
                Debug.Assert(
                    Offline.Phoneme.IsSilenceFeature(phone), 
                    "Silence word should have only one phoneme - silence or short pause.");

                TtsWord silenceWord = utt.AddNewWord(utt.Words[0], InsertOptions.Before);
                ConfigSilenceWord(
                    engine.Phoneme.PronunciationToPhoneIds(Offline.Phoneme.ToRuntime(phone)),
                    silenceWord,
                    utt.Words[0].BreakLevel);
            }

            for (int uttWordIndex = 0; uttWordIndex < utt.Words.Count; uttWordIndex++)
            {
                TtsWord uttWord = utt.Words[uttWordIndex];
                if (uttWord.IsPronounceable)
                {
                    for (; extWordIndex < scriptSentence.Words.Count; extWordIndex++)
                    {
                        if (scriptSentence.Words[extWordIndex].IsPronounced)
                        {
                            extWordIndex++;
                            if (uttWord.BreakLevel < TtsBreakLevel.BK_IDX_INTERM_PHRASE)
                            {
                                if (extWordIndex < scriptSentence.Words.Count &&
                                    scriptSentence.Words[extWordIndex].WordType == WordType.Silence)
                                {
                                    string str1 = "Warning: Script xml has a silence word, ";
                                    string str2 = "but corresponding word[{0}] in engine has a break level ";
                                    string str3 = "less than BK_IDX_INTERM_PHRASE";
                                    TraceLog(logger, true, str1 + str2 + str3, uttWord.WordText);
                                }

                                if (uttWord.Next != null && uttWord.Next.WordType == TtsWordType.WT_SILENCE)
                                {
                                    utt.Delete(uttWord.Next);
                                }
                            }
                            else
                            {
                                if (extWordIndex < scriptSentence.Words.Count &&
                                    scriptSentence.Words[extWordIndex].WordType == WordType.Silence && 
                                    uttWord.Next.WordType != TtsWordType.WT_SILENCE)
                                {
                                    string phone = scriptSentence.Words[extWordIndex].GetPronunciation(phoneSet);
                                    Debug.Assert(
                                        Offline.Phoneme.IsSilenceFeature(phone),
                                        "Silence word should have only one phoneme - silence or short pause.");

                                    TtsWord silenceWord = utt.AddNewWord(uttWord, InsertOptions.After);
                                    ConfigSilenceWord(
                                        engine.Phoneme.PronunciationToPhoneIds(Offline.Phoneme.ToRuntime(phone)),
                                        silenceWord,
                                        uttWord.BreakLevel);
                                }
                                else if (uttWord.Next != null && uttWord.Next.WordType == TtsWordType.WT_SILENCE)
                                {
                                    utt.Delete(uttWord.Next);
                                }
                            }

                            break;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Update word information.
        /// </summary>
        /// <param name="utt">Tts utterance.</param>
        /// <param name="scriptSentence">Script sentence.</param>
        /// <param name="engine">Tts engine.</param>
        private void UpdateWords(SP.TtsUtterance utt, ScriptSentence scriptSentence, TtsEngine engine)
        {
            if (_config.UpdatePronunciation)
            {
                UpdatePronunciation(utt, scriptSentence, engine);
            }

            if (_config.UpdatePartOfSpeech)
            {
                UpdatePartOfSpeech(utt, scriptSentence, engine);
            }
        }