コード例 #1
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
    }
コード例 #2
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
        }
    }