0
\$\begingroup\$

I'm trying to load and play an wav file that exists in my Application.dataPath but when the game gets to the line _GoAudioSource.PlayOneShot(audioLoader.audioClip); It justs throws a empty exception and no sound is played.

I've already checked if the path is correct and it is. I've also tried uploading this wav file to an FTP and loading it via HTTP instead of File:/// but nothing changes.

This is my full code:

     private IEnumerator WriteResponseAudio(ResponseModel res)
     {
         File.WriteAllBytes(Path.Combine(Application.dataPath, FILENAME_RESPONSE), Convert.FromBase64String(res.intent.audio.content));
         string path = "file:///" + Application.dataPath + "/" + FILENAME_RESPONSE;
         WWW audioLoader = new WWW(path);
         yield return audioLoader;
         try
         {
             _GoAudioSource.PlayOneShot(audioLoader.audioClip);
         } catch (Exception ex)
         {
             Debug.LogError("Erro: " + ex.Message);
         }
     }

This is the version with HTTP request:

     private IEnumerator WriteResponseAudio(ResponseModel res)
     {
         File.WriteAllBytes(Path.Combine(Application.dataPath, FILENAME_RESPONSE), Convert.FromBase64String(res.intent.audio.content));
         string path = "http://www.raphaelrosa.com/response.wav";
         WWW audioLoader = new WWW(path);
         yield return audioLoader;
         try
         {
             _GoAudioSource.PlayOneShot(audioLoader.audioClip);
         } catch (Exception ex)
         {
             Debug.LogError("Erro: " + ex.Message);
         }
     }

This is the console:

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Note that Application.dataPath is not necessarily writable. Application.persistentDataPath should be used if you want to write files in a release version. \$\endgroup\$ – DMGregory May 31 '18 at 11:06
1
\$\begingroup\$

I've managed to solve my problem converting my byte array directly in a AudioClip using the code posted by Jeff Kesselman in this topic http://answers.unity3d.com/questions/737002/wav-byte-to-audioclip.html

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.