# Load and play sound in p5.js

**URL:** https://discourse.processing.org/t/load-and-play-sound-in-p5-js/30926
**Category:** Libraries
**Tags:** homework
**Created:** [June 26, 2021, 4:13pm UTC](https://discourse.processing.org/t/load-and-play-sound-in-p5-js/30926 "2021-06-26T16:13:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![cashew](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@cashew](https://discourse.processing.org/u/cashew)
#### Post date: [June 26, 2021, 4:13pm UTC](https://discourse.processing.org/t/load-and-play-sound-in-p5-js/30926/1 "2021-06-26T16:13:17Z")

</div>

Hey there,  
I am new to processing and programming in general.  
What I want to do is load a sound file in Processing P5.js and play it.  
Where do I have to put my sound file in, like is there a folder on my Mac I need to put it in?  
And what about this p5.sound thing??

Thanks for your help guys \<3

---

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [June 26, 2021, 6:18pm UTC](https://discourse.processing.org/t/load-and-play-sound-in-p5-js/30926/2 "2021-06-26T18:18:20Z")

</div>

Hello @cashew ,  
You can find info about how to load/play sound files in the examples section:

[https://p5js.org/examples/sound-load-and-play-sound.html](https://p5js.org/examples/sound-load-and-play-sound.html)

🤓

---

<div class="post-metadata">

### Author: ![cashew](https://avatars.discourse-cdn.com/v4/letter/c/f17d59/32.png) [@cashew](https://discourse.processing.org/u/cashew)
#### Post date: [June 26, 2021, 6:46pm UTC](https://discourse.processing.org/t/load-and-play-sound-in-p5-js/30926/3 "2021-06-26T18:46:15Z")

</div>

I already tried this code. But its not working.  
Whats about the p5.sound library? Do I need this?

---

<div class="post-metadata">

### Author: ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)
#### Post date: [June 26, 2021, 6:54pm UTC](https://discourse.processing.org/t/load-and-play-sound-in-p5-js/30926/4 "2021-06-26T18:54:15Z")

</div>

Do not fear the reference and example pages. Click on the links provided, the information is there!  
🤓

---

<div class="post-metadata">

### Author: ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)
#### Post date: [June 27, 2021, 4:40am UTC](https://discourse.processing.org/t/load-and-play-sound-in-p5-js/30926/5 "2021-06-27T04:40:30Z")

</div>

> Where do I have to put my sound file in, like is there a folder on my Mac I need to put it in?

Generally speaking storing your sound files in the same location as your sketch javascript file, or in a sub directory, are both fine. However, you will need to place it in a location that will be made available by your local web server configuration, and reference it with the appropriate relative or absolute URL. There’s a good [wiki page](https://github.com/processing/p5.js/wiki/Local-server) regarding setting up a local web server. If you try to load your sketch in a web browser directly from a file (i.e. using a URL that starts with `file:///`) then you are going to run into difficulty because web browsers are very strict about loading resources from local files.

> And what about this p5.sound thing??

p5.sound is a separate add-on library that works well with p5.js and follows the same design principles. It can be used to play sound files, synthesize tones, access microphone input, record sound files, and analyze sound frequencies. You can explore the references for this library [here](https://p5js.org/reference/#/libraries/p5.sound). Even though p5.sound is technically a separate library, it is shipped as part of each p5.js release (the current version can be referenced via [https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.3.1/addons/p5.sound.min.js](https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.3.1/addons/p5.sound.min.js) when including it in your sketch HTML file).
