Audio Without User Interaction?

Any way to start audio without having a user click a key or button for p5.js?


You can just call the play() function anywhere to start the sound without having the user to click somewhere.

For example, you can call it in the setup() function (called only once at the beginning of the sketch) :

let mySound;

function preload() {
  soundFormats('mp3', 'ogg');
  mySound = loadSound('assets/doorbell');

function setup() {
  createCanvas(100, 100);

  // Play your sound at startup;

function draw() {
  // Draw something...

(Taken from reference | p5.js)

Thanks!! But what about if I’m trying to trigger a sound with the presence of a certain body part using posenet? The sound won’t automatically play when I use in my function without some sort of click from the user.

I don’t know how posenet works but it depends on the event you want to trigger.

If posenet provides some function to detect some body part, just play your sound file in there.

Otherwise if you want to have a custom behavior, you don’t necessary need some user input to play your sound, just call it in your function.

function detectedSomeBodyPart() {;

  // Do something here...