3

I'm recording with p5.js library but i need to convert the soundFile object to a javascript file object to send it to an audio server.

how can archieve this?

my code is something like this:

mic = new p5.AudioIn();
mic.start();
recorder = new p5.SoundRecorder();
recorder.setInput(mic);
soundFile = new p5.SoundFile();

$("#record").on("click", function{
    recorder.record(soundFile);
})

$("#stop").on("click", function{
    recorder.stop();
})
$("#send").on("click", function{
    //here i need to convert soundFile object to file object 
    myuploadfile(file)
})
2
  • Should be in soundFile.path. Commented Jul 26, 2016 at 22:21
  • I'm not sure what you're asking. What exactly do you mean by "javascript file object"? Can you please provide a minimal reproducible example or a jsfiddle that we can play with? Commented Jul 27, 2016 at 12:44

2 Answers 2

4

The p5.sound library creates a Blob object before download it as .wav, you can see this on p5.prototype.writeFile.

The difference between a Blob and a file is just 2 extra properties: a date and a name, so, if you want to "convert" your blob to a file, just add this 2 properties:

function blobToFile(theBlob, fileName){
    //A Blob() is almost a File() - it's just missing the two properties below which we will add
    theBlob.lastModifiedDate = new Date();
    theBlob.name = fileName;
    return theBlob;
}

After that, you can manage the output as a javascript file

Sign up to request clarification or add additional context in comments.

Comments

0

Here is the example you seek to do a recording and playback. After saveSound(soundFile, 'mySound.wav'); you should be able to access soundFile.path to get the path. Of course, that will just download mySound.wav to your Browser.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.