Example #1
0
        private void speakNative(Model.Wrapper wrapper)
        {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            SpVoice speechSynthesizer = new SpVoice();

            SpObjectToken voice = getSapiVoice(wrapper.Voice);

            if (voice != null)
            {
                speechSynthesizer.Voice = voice;
            }

            speechSynthesizer.Volume = calculateVolume(wrapper.Volume);
            speechSynthesizer.Rate   = calculateRate(wrapper.Rate);

            System.Threading.Thread worker = new System.Threading.Thread(() => speechSynthesizer.Speak(prepareText(wrapper), wrapper.ForceSSML && !Speaker.isAutoClearTags ? SpeechVoiceSpeakFlags.SVSFIsXML : SpeechVoiceSpeakFlags.SVSFIsNotXML));
            worker.Start();

            do
            {
                System.Threading.Thread.Sleep(50);
            } while (worker.IsAlive && !silence);

            if (silence)
            {
                speechSynthesizer.Skip("Sentence", int.MaxValue);
            }

            //speechSynthesizer.WaitUntilDone(int.MaxValue);
#endif
        }
 /// <summary>
 /// <c>OnApplicationQuit</c>
 ///
 /// Description: takes care of speechLib talking once the main thread is terminated.
 ///
 /// Pre-condition: None
 ///
 /// Post-condition: stops AI from speaking in world.
 ///
 /// </summary>
 /// <returns>NULL</returns>
 public void OnApplicationQuit()
 {
     // Because we create a new thread when the NPC speaks, it wont stop once the main thread application stops running.
     if (newThread != null)
     {
         if (newThread.IsAlive)
         {
             // skip the squence, and finish it.
             voice.Skip("Sentence", int.MaxValue);
         }
     }
 }
Example #3
0
 public void Kill()
 {
     Voice?.Skip("Sentence", int.MaxValue);
     Thread.Abort();
 }
Example #4
0
 void SpeakPlayerList()
 {
     spVoice.Skip("Sentence", int.MaxValue);
     spVoice.Speak(PlayerList.Instance.text.text);
 }