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(){ +}