Home Save Recorded Audio to Local Directory -ReactJS
Reply: 0

Save Recorded Audio to Local Directory -ReactJS

user1266
1#
user1266 Published in May 28, 2018, 3:05 am

I am recording an audio through browser and storing it as a blob using react-mic library, I need to change the blob audio file to mp3/ogg/wav file and store it in local directory using ReactJS.

Blob example:

{blob: Blob(5899), startTime: 1518600546820, stopTime: 1518600547833, options: {audioBitsPerSecond :128000, mimeType:"audio/mpeg"}, blobURL: "blob:http://localhost:3000/3ac81ece-237f-4265-8225-6653b2beb0bc"}

Here I am storing a blob in a state,

onStop = (recordedBlob) => {
    this.setState({
        blobMain: recordedBlob
    })
}

instead of a blob I wanted to store a mp3/ogg/wav file. And use the state for api response.

I tried using Filereader() to convert the blob to ArrayBuffer and convert it as a mp3/ogg/wave file.

onStop = (recordedBlob) => {
    var arrayBuffer;
    var fileReader = new FileReader();
    fileReader.onload = function() {
        arrayBuffer = this.result;
    };
    fileReader.readAsArrayBuffer(recordedBlob);
    this.setState({
        blobMain: fileReader
    })
}

But I get an error as:

TypeError: Failed to execute 'readAsArrayBuffer' on 'FileReader': parameter 1 is not of type 'Blob'.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300803 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO