# Having trouble getting p5.SoundRecorder to work

**URL:** https://discourse.processing.org/t/having-trouble-getting-p5-soundrecorder-to-work/44626
**Category:** Libraries
**Created:** [June 22, 2024, 2:43am UTC](https://discourse.processing.org/t/having-trouble-getting-p5-soundrecorder-to-work/44626 "2024-06-22T02:43:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ASKproduKtion](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/askproduktion/32/19695_2.png) [@ASKproduKtion](https://discourse.processing.org/u/ASKproduKtion)
#### Post date: [June 22, 2024, 2:43am UTC](https://discourse.processing.org/t/having-trouble-getting-p5-soundrecorder-to-work/44626/1 "2024-06-22T02:43:17Z")

</div>

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](https://p5js.org/reference/#/p5.SoundRecorder)

following is the p5.js project \>\> [p5.js Web Editor](https://editor.p5js.org/gradientsASK/sketches/Bch9xA2bU)

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

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [June 23, 2024, 8:32pm UTC](https://discourse.processing.org/t/having-trouble-getting-p5-soundrecorder-to-work/44626/2 "2024-06-23T20:32:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ASKproduKtion](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/askproduktion/32/19695_2.png) [@ASKproduKtion](https://discourse.processing.org/u/ASKproduKtion)
#### Post date: [June 25, 2024, 3:33pm UTC](https://discourse.processing.org/t/having-trouble-getting-p5-soundrecorder-to-work/44626/3 "2024-06-25T15:33:30Z")

</div>

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](http://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

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [June 26, 2024, 6:06am UTC](https://discourse.processing.org/t/having-trouble-getting-p5-soundrecorder-to-work/44626/4 "2024-06-26T06:06:00Z")

</div>

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](https://github.com/processing/p5.sound.js)
