Home

Awesome

Wav Utility for Unity

WAV utility for recording and audio playback functions in Unity.

Usage

Notes

By design the ToAudioClip method only supports loading wav files that are stored using Unity's Application data path (Application.persistentDataPath or Application.dataPath). In order to load bundled resources it would be better to use Unity's Resources.Load("filename") typeof(AudioClip) method.

If you need to load WAV files from a remote URL then use the UnityWebRequest.GetAudioClip method which uses the AudioClip download handler.

public void LoadAudio ()
{
  string url = "<WAV_FILE_URL>";
  StartCoroutine (LoadAudioURL (url));
}
public IEnumerator LoadAudioURL (string url)
{
  UnityWebRequest www = UnityWebRequest.GetAudioClip (url, AudioType.WAV);
  yield return www.Send ();
  if (www.isError) {
    Debug.LogWarning ("Audio error:" + www.error);
  } else {
    AudioClip audioClip = ((DownloadHandlerAudioClip)www.downloadHandler).audioClip;
    audioSource.clip = audioClip;
    audioSource.Play ();
  }
}

Version history

Related info

Wav file formatting based on specs detailed in following articles:

Share the <3 @deadlyfingers