c# – Audio plays in editor but not on mobile

Question:

I'm making a narrated game for android in unity 5 with c#, i use the following function to get the audio from the google voice. But it only works in the editor, when I have it installed on my cell phone the audio doesn't play, I checked if the device has sound, I increased the volume, I tried it on other devices and always the same thing.

public AudioSource _audio;
public string textoATocar;


// Use this for initialization
void Start () {
   _audio = gameObject.GetComponent<AudioSource> ();
}

public void tocaIsso( string audioTocar){
   StartCoroutine( DownloadAudio( audioTocar ) );
}

IEnumerator DownloadAudio( string textoATocar2 ){
   string url = "http://translate.google.com/translate_tts?ie=UTF-8&total=1&idx=0&textlen=32&client=tw-ob&q=" + textoATocar2 + "&tl=Pt-gb";
   WWW www = new WWW(url);
   yield return www;

   _audio.clip = www.GetAudioClip( false, true, AudioType.MPEG );
   _audio.Play();
}

Ps: I call the function like this, textAudio.tocaIsso(opcoesMenu[ posicaoMenu ]); , which serves to narrate the menu.

Edit: I updated my unity to the latest version and now I get an error,

Error: Cannot create FMOD::Sound instance for resource Ȯ1C, (Operation could not be performed because specified sound/DSP connection is not ready. )
UnityEngine.WWWAudioExtensions:GetAudioClip(WWW, Boolean, Boolean, AudioType)
<DownloadAudio>c__Iterator0:MoveNext() (at Assets/Scripts/TextoToAudio.cs:27)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

but I've already looked for everything, and I haven't found a way around it.

Answer:

I found out that this is a bug in the engine itself, and so far 10/30/2017 it hasn't been fixed, but it happens in audio stream.

Scroll to Top