Sound api - help

####1. Describe Your Issue

Is there an example using the sound api?

I need another set of eyes;) I’m getting “.playOnce is not a function” which probably means something very simple but I can’t see it.

let audioObj = soundsUtils.playOnce(fileName,audioCallback);

fragment:

let fileName="…/src/audio/sample1.mp3";

let soundsUtils = new jibo.sound.SoundsUtils();
console.log(‘SoundsUtils’,soundsUtils);

let audioObj = soundsUtils.playOnce(fileName,audioCallback);
console.log(‘audioObj’,audioObj);

other:
I’ve been using another audio library that uses either web audio api or defaults to html5 audio - I can’t really decide whether to use the native jibo sound lib. I don’t have a feel for the pro/cons about using external lib yet. If there’s any feedback, please add to the documentation.

thanks for the help

Hi Bob,

I may need more info on what you’re trying to do with the API but I can absolutely provide a working example of the sound API that I hope will be helpful.

In your example it looked like you were using the SoundsUtils class but for most use cases you shouldn’t need that class. The Sound class and jibo/sound module here should do the trick for most sound management.

A working example of API can be seen by using the following code in an ExecuteScript behavior:

() => {
  
  jibo.sound.add()
  notepad.sound = jibo.sound.add('bleep', {
    
    src: 'audio/FX_Bleep.mp3',  // location in file system
    preload: false,              // start loading the sound right away?
    autoPlay: false,             // start playing the sound immediately after loading?
    loop: false,                // loop my sound? (false by default)
    block: false,                // allow other sounds to play over this sound? (false by default)
    // useXHR: true,  //commented out, neccesary to use if your src is set to an external URL
  });
  jibo.sound.play('bleep');     // load sound and play it based on the options it was created with
  
}

The major thing to keep in mind if you are using an external audio source is that you will need to edit the src accordingly and make sure to have useXHR: true. I included that with a comment in the above code.

I hope that is a helpful example!

-John

3 Likes

Thank you John! Your example is helpful. I get it now. It looks like I can add a map as well.
Handling audio sprites is another topic …I’ll see how that goes

Best Bob