# GetAudioClip

> Create a UnityWebRequest to download an audio clip via HTTP GET and create an AudioClip based on the retrieved data.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.Networking](/engine/6000.5/script-reference/unityengine/networking.md)
* **Assembly:** UnityEngine.UnityWebRequestAudioModule

## GetAudioClip(string, AudioType)

Create a [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md) to download an audio clip via HTTP GET and create an [AudioClip](/engine/6000.5/script-reference/unityengine/audioclip.md) based on the retrieved data.

```csharp
public static UnityWebRequest GetAudioClip(string uri, AudioType audioType)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The URI of the audio clip to download.**** (\[AudioType]\(/engine/6000.5/script-reference/unityengine/audiotype)): The type of audio encoding for the downloaded audio clip. See [AudioType](/engine/6000.5/script-reference/unityengine/audiotype.md).

### Returns

| Type                                                                                         | Description                                                                                                                                                                                                                              |
| -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md) | A [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md) properly configured to download an audio clip and convert it to an [AudioClip](/engine/6000.5/script-reference/unityengine/audioclip.md). |

### Remarks

This method creates a [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md) and sets the target URL to the string `uri` argument. This method sets no other flags or custom headers.

This method attaches a [DownloadHandlerAudioClip](/engine/6000.5/script-reference/unityengine/networking/downloadhandleraudioclip.md) object to the [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md). [DownloadHandlerAudioClip](/engine/6000.5/script-reference/unityengine/networking/downloadhandleraudioclip.md) is a specialized [DownloadHandler](/engine/6000.5/script-reference/unityengine/networking/downloadhandler.md). It is optimized for storing data which is to be used as an audio clip in the Unity Engine. Using this class significantly reduces memory reallocation compared to downloading raw bytes and creating an audio clip manually in script.

This method attaches no [UploadHandler](/engine/6000.5/script-reference/unityengine/networking/uploadhandler.md) to the [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md).

### Examples

```csharp
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class MyBehaviour : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(GetAudioClip());
    }

    IEnumerator GetAudioClip()
    {
        using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("https://www.my-server.com/audio.ogg", AudioType.OGGVORBIS))
        {
            yield return www.SendWebRequest();

            if (www.result == UnityWebRequest.Result.ConnectionError)
            {
                Debug.Log(www.error);
            }
            else
            {
                AudioClip myClip = DownloadHandlerAudioClip.GetContent(www);
            }
        }
    }
}
```

## GetAudioClip(Uri, AudioType)

Create a [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md) to download an audio clip via HTTP GET and create an [AudioClip](/engine/6000.5/script-reference/unityengine/audioclip.md) based on the retrieved data.

```csharp
public static UnityWebRequest GetAudioClip(Uri uri, AudioType audioType)
```

### Parameters

**** (\[Uri]\(https\://learn.microsoft.com/dotnet/api/system.uri)): The URI of the audio clip to download.**** (\[AudioType]\(/engine/6000.5/script-reference/unityengine/audiotype)): The type of audio encoding for the downloaded audio clip. See [AudioType](/engine/6000.5/script-reference/unityengine/audiotype.md).

### Returns

| Type                                                                                         | Description                                                                                                                                                                                                                              |
| -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md) | A [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md) properly configured to download an audio clip and convert it to an [AudioClip](/engine/6000.5/script-reference/unityengine/audioclip.md). |

### Remarks

This method creates a [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md) and sets the target URL to the string `uri` argument. This method sets no other flags or custom headers.

This method attaches a [DownloadHandlerAudioClip](/engine/6000.5/script-reference/unityengine/networking/downloadhandleraudioclip.md) object to the [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md). [DownloadHandlerAudioClip](/engine/6000.5/script-reference/unityengine/networking/downloadhandleraudioclip.md) is a specialized [DownloadHandler](/engine/6000.5/script-reference/unityengine/networking/downloadhandler.md). It is optimized for storing data which is to be used as an audio clip in the Unity Engine. Using this class significantly reduces memory reallocation compared to downloading raw bytes and creating an audio clip manually in script.

This method attaches no [UploadHandler](/engine/6000.5/script-reference/unityengine/networking/uploadhandler.md) to the [UnityWebRequest](/engine/6000.5/script-reference/unityengine/networking/unitywebrequest.md).

### Examples

```csharp
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class MyBehaviour : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(GetAudioClip());
    }

    IEnumerator GetAudioClip()
    {
        using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("https://www.my-server.com/audio.ogg", AudioType.OGGVORBIS))
        {
            yield return www.SendWebRequest();

            if (www.result == UnityWebRequest.Result.ConnectionError)
            {
                Debug.Log(www.error);
            }
            else
            {
                AudioClip myClip = DownloadHandlerAudioClip.GetContent(www);
            }
        }
    }
}
```
