예제 #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
    }
예제 #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
    }
예제 #3
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());
        }
    }
예제 #4
0
    void OnDestroy()
    {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
        // NOP.
#elif UNITY_ANDROID
        if (UAP_AccessibilityManager.UseAndroidTTS())
        {
            AndroidTTS.StopSpeaking();
            AndroidTTS.Shutdown();
        }
#elif UNITY_IOS
        if (UAP_AccessibilityManager.UseiOSTTS())
        {
            iOSTTS.StopSpeaking();
            iOSTTS.Shutdown();
        }
#endif
    }
예제 #5
0
        IEnumerator WaitForUapToStopSpeaking()
        {
            while (AndroidTTS.IsSpeaking() == true)
            {
                yield return(null);
            }
#if UNITY_IOS
            while (iOSTTS.IsSpeaking() == true)
            {
                yield return(null);
            }
#endif
            Finish();
            if (finishEvent != null)
            {
                Fsm.Event(finishEvent);
            }
        }
    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();
        }
    }
예제 #7
0
    //////////////////////////////////////////////////////////////////////////

    public void Initialize()
    {
        m_SpeechRate = PlayerPrefs.GetInt("Accessibility_Speech_Rate", 50);

        if (m_AudioPlayer == null)
        {
            m_AudioPlayer = GetComponent <AudioSource>();
        }

#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
        // Initialize Text To Speech for Windows platforms - if so desired
        if (UAP_AccessibilityManager.UseWindowsTTS())
        {
            if (WindowsTTS.instance == null)
            {
                GameObject WindowsTTSObj = new GameObject("Windows TTS");
                WindowsTTSObj.AddComponent <WindowsTTS>();
            }
        }
#elif (UNITY_STANDALONE_OSX || UNITY_EDITOR) && !UNITY_WEBPLAYER
        // Initialize Text To Speech for Mac platform - if so desired
        if (UAP_AccessibilityManager.UseMacOSTTS())
        {
            if (MacOSTTS.instance == null)
            {
                GameObject MacOSTTSObj = new GameObject("MacOS TTS");
                MacOSTTSObj.AddComponent <MacOSTTS>();
            }
        }
#elif UNITY_ANDROID && !UNITY_EDITOR
        if (UAP_AccessibilityManager.UseAndroidTTS())
        {
            AndroidTTS.Initialize();
        }
#elif UNITY_IOS && !UNITY_EDITOR
        if (UAP_AccessibilityManager.UseiOSTTS())
        {
            iOSTTS.Init();
        }
#endif
    }
예제 #8
0
    //////////////////////////////////////////////////////////////////////////

    public void Initialize()
    {
        m_SpeechRate = PlayerPrefs.GetInt("Accessibility_Speech_Rate", 50);

        if (m_AudioPlayer == null)
        {
            m_AudioPlayer = GetComponent <AudioSource>();
        }

        // Initialize which custom TTS to use, if any
        InitializeCustomTTS();

        //////////////////////////////////////////////////////////////////////////
        // For WebGL, we need a custom TTS solution
        // The following code makes sure that there is either a custom TTS already set up, or it tries to
        // initialize the included Google Cloud TTS API. This can only be done if an API key is provided.
#if UNITY_WEBGL
        if (Application.platform == RuntimePlatform.WebGLPlayer && UAP_AccessibilityManager.UseWebGLTTS())
        {
            if (UAP_CustomTTS.IsInitialized() == UAP_CustomTTS.TTSInitializationState.NotInitialized)
            {
                // Use Google TTS if set up correctly, or internal TTS otherwise
                if (!string.IsNullOrEmpty(UAP_AccessibilityManager.GoogleTTSAPIKey))
                {
                    UAP_CustomTTS.InitializeCustomTTS <Google_TTS>();
                }
                else
                {
                    UAP_CustomTTS.InitializeCustomTTS <WebSpeechAPI_TTS>();
                }
            }
        }
#endif
        //////////////////////////////////////////////////////////////////////////

        if (UAP_CustomTTS.IsInitialized() == UAP_CustomTTS.TTSInitializationState.NotInitialized)
        {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            // Initialize Text To Speech for Windows platforms - if so desired

            /*
             * No more auto-initialization
             *                      if (UAP_AccessibilityManager.UseWindowsTTS())
             *                      {
             *                              InitializeWindowsTTS();
             *                      }
             */
#elif (UNITY_STANDALONE_OSX || UNITY_EDITOR) && !UNITY_WEBPLAYER
            // Initialize Text To Speech for Mac platform - if so desired
            if (UAP_AccessibilityManager.UseMacOSTTS())
            {
                if (MacOSTTS.instance == null)
                {
                    GameObject MacOSTTSObj = new GameObject("MacOS TTS");
                    MacOSTTSObj.AddComponent <MacOSTTS>();
                    MacOSTTSObj.transform.SetParent(this.transform, false);
                }
            }
#elif UNITY_ANDROID && !UNITY_EDITOR
            if (UAP_AccessibilityManager.UseAndroidTTS())
            {
                AndroidTTS.Initialize();
            }
#elif UNITY_IOS && !UNITY_EDITOR
            if (UAP_AccessibilityManager.UseiOSTTS())
            {
                iOSTTS.Init();
            }
#endif
        }
    }