コード例 #1
0
    IEnumerator RunPlayVoice()
    {
        OnGetVoiceStart();

        text = _inputField.text;
        int    languageIndex    = _languageDropDownList.value;
        int    audioCodecsIndex = _audioCodecsDropDownList.value;
        string url = manager.GetTextToSpeechAudioWithIndex(text, languageIndex, audioCodecsIndex);
        WWW    www = new WWW(url);

        yield return(www);

        AudioClip clip = www.GetAudioClip(false, false, manager.GetCurrentAudioTypeWithIndex(audioCodecsIndex));

        if (clip.length > 0 && clip != null)
        {
            _audioSource.clip = clip;
            _audioSource.Play();
        }
        else
        {
            Debug.LogError("Failed to get the voice. Please try:\n" +
                           "1.Try it in other languages.\n" +
                           "2.Fill in something in text field.\n" +
                           "3.Choose the correct audio format.");
        }

        OnGetVoiceEnd();
    }