Example #1
0
    void StopAudio()
    {
        if (m_AudioPlayer.isPlaying)
        {
            m_AudioPlayer.Stop();
            m_AudioPlayer.clip = null;
        }

#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
        if (UAP_AccessibilityManager.UseWindowsTTS())
        {
            WindowsTTS.Stop();
        }
#elif (UNITY_STANDALONE_OSX || UNITY_EDITOR) && !UNITY_WEBPLAYER
        if (UAP_AccessibilityManager.UseMacOSTTS())
        {
            MacOSTTS.instance.Stop();
        }
#elif UNITY_ANDROID
        if (UAP_AccessibilityManager.UseAndroidTTS())
        {
            m_TTS_SpeakingTimer = 0.0f;
            AndroidTTS.StopSpeaking();
        }
#elif UNITY_IOS
        if (UAP_AccessibilityManager.UseiOSTTS())
        {
            m_TTS_SpeakingTimer = 0.0f;
            iOSTTS.StopSpeaking();
        }
#endif
    }
Example #2
0
    //////////////////////////////////////////////////////////////////////////

    void TTS_Speak(string text, bool allowVoiceOver = true)
    {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
        if (UAP_AccessibilityManager.UseWindowsTTS())
        {
            //Debug.Log("Speaking: " + text);
            WindowsTTS.Speak(text);
        }
#elif (UNITY_STANDALONE_OSX || UNITY_EDITOR) && !UNITY_WEBPLAYER
        if (UAP_AccessibilityManager.UseMacOSTTS())
        {
            //Debug.Log("Speaking: " + text);
            MacOSTTS.instance.Speak(text);
        }
#elif UNITY_ANDROID
        if (UAP_AccessibilityManager.UseAndroidTTS())
        {
            m_TTS_SpeakingTimer += (text.Length * 3.0f / 16.0f);
            AndroidTTS.SetSpeechRate(m_SpeechRate);
            AndroidTTS.Speak(text);
        }
#elif UNITY_IOS
        if (UAP_AccessibilityManager.UseiOSTTS())
        {
            m_TTS_SpeakingTimer += (text.Length * 3.0f / 16.0f);
            iOSTTS.StartSpeaking(text, allowVoiceOver && UAP_AccessibilityManager.IsVoiceOverAllowed(), m_SpeechRate);
        }
#endif
    }
/*
 *      //////////////////////////////////////////////////////////////////////////
 *
 *      public static void SetSpeechVolume(int volume)
 *      {
 *              SetVolume(volume);
 *      }
 *
 *      //////////////////////////////////////////////////////////////////////////
 *
 *      public static void SetSpeechRate(int rate)
 *      {
 *              SetRate(rate);
 *      }
 */

    //////////////////////////////////////////////////////////////////////////

    void OnDestroy()
    {
        if (instance == this)
        {
            DestroySpeech();
            instance = null;
        }
    }
Example #4
0
    bool TTS_IsSpeaking()
    {
        if (UAP_CustomTTS.IsInitialized() == UAP_CustomTTS.TTSInitializationState.NotInitialized)
        {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            if (UAP_AccessibilityManager.UseWindowsTTS() && WindowsTTS.instance != null)
            {
                return(WindowsTTS.IsSpeaking());
            }
            else
            {
                return(false);
            }
#elif (UNITY_STANDALONE_OSX || UNITY_EDITOR) && !UNITY_WEBPLAYER
            if (UAP_AccessibilityManager.UseMacOSTTS())
            {
                return(MacOSTTS.instance.IsSpeaking());
            }
            else
            {
                return(false);
            }
#elif UNITY_ANDROID
            return(AndroidTTS.IsSpeaking());

            //bool isTTSSpeaking = AndroidTTS.IsSpeaking();
            //if (!isTTSSpeaking)
            //  return false;
            //return m_TTS_SpeakingTimer > 0.0f;
#elif UNITY_IOS
            // VoiceOver sometimes times out without notification
            if (!m_LastEntryUsedVoiceOver)
            {
                return(iOSTTS.IsSpeaking());
            }
            // VoiceOver is not 100% reliable unfortunately
            bool VOSpeaking = iOSTTS.IsSpeaking();
            if (!VOSpeaking)
            {
                return(false);
            }
            return(m_TTS_SpeakingTimer > 0.0f);
#else
            return(false);
#endif
        }
        else
        {
            return(UAP_CustomTTS.IsSpeaking());
        }
    }
    void StopAudio(bool includingAndroid = false)
    {
        if (m_AudioPlayer.isPlaying)
        {
            m_AudioPlayer.Stop();
            m_AudioPlayer.clip = null;
        }

        if (UAP_CustomTTS.IsInitialized() == UAP_CustomTTS.TTSInitializationState.NotInitialized)
        {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            if (UAP_AccessibilityManager.UseWindowsTTS() && WindowsTTS.instance != null)
            {
                WindowsTTS.Stop();
            }
#elif (UNITY_STANDALONE_OSX || UNITY_EDITOR) && !UNITY_WEBPLAYER
            if (UAP_AccessibilityManager.UseMacOSTTS())
            {
                MacOSTTS.instance.Stop();
            }
#elif UNITY_ANDROID
            if (UAP_AccessibilityManager.UseAndroidTTS())
            {
                m_TTS_SpeakingTimer = 0.0f;
                if (includingAndroid)
                {
                    AndroidTTS.StopSpeaking();
                }
            }
#elif UNITY_IOS
            if (UAP_AccessibilityManager.UseiOSTTS())
            {
                m_TTS_SpeakingTimer = 0.0f;
                iOSTTS.StopSpeaking();
            }
#endif
        }
        else
        {
            UAP_CustomTTS.Stop();
        }
    }
    //////////////////////////////////////////////////////////////////////////

    void Start()
    {
        if (instance == null)
        {
            instance = this;
            Initialize();

            // No longer needed, because this is now a child of the Accessibility Manager, which is already set to DontDestroyOnLoad
            //DontDestroyOnLoad(gameObject);
        }
        else
        {
            Debug.LogError("[Accessibility] Trying to create another Windows TTS instance, when there already is one.");
            DestroyImmediate(gameObject);
            return;
        }

        //Debug.Log("[Accessibility] TTS: NVDA " + (m_UseNVDA ? "detected." : "not detected"));

        //bool isWindows = Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer;
        //Debug.Log("[Accessibility] TTS: Window SAPI " + (isWindows ? "detected." : "not detected"));
    }
Example #7
0
 void Awake()
 {
     tts = new WindowsTTS();
 }