# loadSound()

### Example

click the link below to play the sound.

{% file src="<https://768248463-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fqbs7pgU3AVBY06Rl9M31%2Fuploads%2Fa5KVZVuWIiCsivYoOK77%2Fwow-121578.mp3?alt=media&token=4a2a53c1-791b-422d-974b-b4fd87d14595>" %}
Sound Effect by [UNIVERSFIELD](https://pixabay.com/users/universfield-28281460/?utm_source=link-attribution\&utm_medium=referral\&utm_campaign=music\&utm_content=121578) from [Pixabay](https://pixabay.com/sound-effects/?utm_source=link-attribution\&utm_medium=referral\&utm_campaign=music\&utm_content=121578)
{% endfile %}

```python
def setup():
    ...
    loadSound("/wow-121578.mp3",'WOW')

def draw():
    ...
    assets['WOW'].play()
```

### Syntax

```python
def setup():
    ...
    loadSound("sourceURL",'NAME')

def draw():
    ...
    assets['NAME'].play()
    ...
    assets['NAME'].stop()
```

| Input     | Description                                |
| --------- | ------------------------------------------ |
| sourceURL | web or local URL of **sound** to be loaded |
| NAME      | name for **variable** of sound in code     |

### Description

Loads a sound into memory from an external source so that it can be used in code. The **sourceURL** can be a web address (for example **"<http://wow-121578.mp3>"**) - this is the usual situation - or the local address if the file is stored with the rest of your code.&#x20;

Once a sound is loaded (in the example below, using the variable **'NAME'** in code), the following functions are available to call on the sound file:

| Function                      | Description                                                                                                                                                                                   |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| assets\['NAME'].play()        | starts playing the sound                                                                                                                                                                      |
| assets\['NAME'].stop()        | stops playing the sound and resets it                                                                                                                                                         |
| assets\['NAME'].pause()       | stops playing the sound and pauses it                                                                                                                                                         |
| assets\['NAME'].isPlaying()   | returns `True` or `False` depending on whether the sound is currently already playing                                                                                                         |
| assets\['NAME'].volume(**V**) | <p>adjusts the volume of the sound. <strong>V</strong> is a decimal value <strong>between 0 and 1</strong>. </p><p><strong>0</strong> is no volume, <strong>1</strong> is maximum volume </p> |

{% hint style="info" %}
Find these documents helpful? Let the people who made them help your child learn to code at [**Strivemath**](https://www.strivemath.com/)<mark style="color:blue;">**!**</mark>

We'd love to hear your Feedback/Comments [here](https://docs.google.com/forms/d/e/1FAIpQLSeqorBAGTya-YBRI-VFjJxtgQtCz3ucGDI96K96sNyuaGuvdw/viewform?usp=sf_link).
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnpython.strivemath.com/p5-python-web/reference/images-and-audio/loadsound.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
