Having trouble getting p5.SoundRecorder to work

I have a p5.js sketch that integrates some Tone.js music functions adapted from @mattdesl

I have added a p5.SoundRecorder from reference | p5.js

following is the p5.js project >> p5.js Web Editor

my intention is to manually stop recording and save the file by inserting code into the console while the sketch is running >>
recorder.stop();
save(soundFile, ‘soundASK.wav’);

this saves a wav file of the correct time duration, but the sound is empty.

according to SoundRecorder reference on p5js dot org “If no parameter is given, p5.SoundRecorer will record all audible p5.sound from your sketch.”

so I don’t understand why I am getting an empty silent wav file (the time duration is correct, so something is recording something, but not the sound emanating from my sketch).

thank you in advance for any assistance

1 Like

I’m not familiar with the technique of manually recording and saving a file by inserting code into the console of p5.js. Have you tried inserting three buttons into your sketch: one for ‘begin record’, one for ‘end record’, and one for ‘playback’ and then hooking them up to the appropriate code? The demo for p5.SoundRecorder works well for a desktop microphone, and supposedly it can also record sketch generated sound. What have you tried and what code did you use?

Addendum:
I just tested p5.SoundRecorder without a microphone using a coded synthesizer and it recorded and played back the sound correctly, so it appears to work as advertised on MacOS. I can also confirm that using the ASK synthesizer code causes empty .wav files to be created for reasons unknown to me. Your issue may not have anything to do with your code but appears to be related to the synthesizer. You might want to write some of your own synthesizer code and see how p5.SoundRecorder performs with another synth. It does work with a microphone, but then you’ll hear the mouse clicks too.

Hello Svan, thanks for getting back. Re manually inserting code into the p5.js console, I employ this technique regularly, for example saveCanvas(); to take stills from my sketch. In this case, it appears to work fine to a/ stop the recording and then b/ save the wav file of the correct time duration.

Re your addendum, I suspect indeed it may have something to do with the synth, although per p5.org the SoundRecorder should record all sound emanating from the sketch. Alas, it’s specifically the sound from this synth that I’m looking to record.

Thanks anyways, cheers

I feel this is due to the scope (inside draw etc vs global) but I haven’t tested it yet so not sure. I guess opening an issue would help especially when someone else has a same problem GitHub - processing/p5.sound.js: new build of p5.sound.js library