Load and play sound in p5.js

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

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



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

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

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 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. 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 when including it in your sketch HTML file).

1 Like