From ed44d61f51a5cbde1e659ed8c8193b5384acbea6 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 18 Dec 2019 13:06:32 +0700 Subject: [PATCH] Improve record/stop/play handling --- vocoder/static/vocoder.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/vocoder/static/vocoder.js b/vocoder/static/vocoder.js index a1db23e..baca1f3 100644 --- a/vocoder/static/vocoder.js +++ b/vocoder/static/vocoder.js @@ -10,33 +10,37 @@ var serverUrl = 'http://localhost:5000'; var archiveUrl = serverUrl + '/add-to-archive/'; -function setupRecording(){ - var mic, recorder, soundFile; - var state = 0; +var mic, recorder, soundFile; +var state = 0; + +// 30 seconds (in milliseconds) +var recordingTimeout = 30000; +function setupRecording(){ mic = new p5.AudioIn(); mic.start(); + recorder = new p5.SoundRecorder(); recorder.setInput(mic); + soundFile = new p5.SoundFile(); function doRecording(){ - // TODO: handle timing out if no stopping happens if (mic.enabled){ - recorder.record(soundFile); + setTimeout(recorder.record(soundFile), recordingTimeout); } }; function doStopping(){ - // TODO: only stop if playing/recording otherwise: - // "NotSupportedError: Operation is not supported" - recorder.stop(); - - // TODO: handle the generation of shapes from here + if (recorder.recording) { + recorder.stop(); + } }; function doPlaying(){ - soundFile.play(); + if (soundFile.isLoaded()){ + soundFile.play(); + } }; function doArchiving(){ @@ -80,4 +84,5 @@ function setup(){ setupRecording(); } -function draw(){} +function draw(){ +}