Browse Source

Improve record/stop/play handling

main
Luke Murphy 4 years ago
parent
commit
ed44d61f51
No known key found for this signature in database GPG Key ID: 5E2EF5A63E3718CC
  1. 29
      vocoder/static/vocoder.js

29
vocoder/static/vocoder.js

@ -10,33 +10,37 @@
var serverUrl = 'http://localhost:5000'; var serverUrl = 'http://localhost:5000';
var archiveUrl = serverUrl + '/add-to-archive/'; var archiveUrl = serverUrl + '/add-to-archive/';
function setupRecording(){ var mic, recorder, soundFile;
var mic, recorder, soundFile; var state = 0;
var state = 0;
// 30 seconds (in milliseconds)
var recordingTimeout = 30000;
function setupRecording(){
mic = new p5.AudioIn(); mic = new p5.AudioIn();
mic.start(); mic.start();
recorder = new p5.SoundRecorder(); recorder = new p5.SoundRecorder();
recorder.setInput(mic); recorder.setInput(mic);
soundFile = new p5.SoundFile(); soundFile = new p5.SoundFile();
function doRecording(){ function doRecording(){
// TODO: handle timing out if no stopping happens
if (mic.enabled){ if (mic.enabled){
recorder.record(soundFile); setTimeout(recorder.record(soundFile), recordingTimeout);
} }
}; };
function doStopping(){ function doStopping(){
// TODO: only stop if playing/recording otherwise: if (recorder.recording) {
// "NotSupportedError: Operation is not supported" recorder.stop();
recorder.stop(); }
// TODO: handle the generation of shapes from here
}; };
function doPlaying(){ function doPlaying(){
soundFile.play(); if (soundFile.isLoaded()){
soundFile.play();
}
}; };
function doArchiving(){ function doArchiving(){
@ -80,4 +84,5 @@ function setup(){
setupRecording(); setupRecording();
} }
function draw(){} function draw(){
}

Loading…
Cancel
Save