Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blob show type as audio/wav but still show up as webm after converted to Base64 #101

Open
andrewroar opened this issue Jun 2, 2022 · 4 comments

Comments

@andrewroar
Copy link

After recording and recieve the blob as audio/wav, I use new FileReader().readAsDataURL(blob) to convert to base64. I then tried to convert it back to audio with the following website (https://base64.guru/converter/decode/audio) but it indicates it as webm.

I am trying to pass the base64 to another api which only support wav. The base64 I got from converting the blob currently does not work despite working with other wav files we tested it with.

@ramonrovirosa
Copy link

@andrewroar did you end up figuring this out? Facing the same issue.

@andrewroar
Copy link
Author

@ramonrovirosa I'm afraid not. I end up just writing my own recorder instead.

@ramonrovirosa
Copy link

ramonrovirosa commented Apr 6, 2023

In case it helps anyone in the future, what I did was pass the file as a base64 string to the server and on the server using ffmpeg, I converted the file to an mp3. That finally worked. Something like this

Frontend React

//Initialization
const { status, startRecording, stopRecording, mediaBlobUrl } =
    useReactMediaRecorder({ video: false, audio: true });

//Handling of media URL
const blobToBase64 = async (url) => {
  return new Promise(async (resolve, _) => {
    const blob = await fetch(url).then(r => r.blob());

    // instantiate a file reader
    const fileReader = new FileReader();

    // read the file
    fileReader.readAsDataURL(blob);

    fileReader.onloadend = () => {
      resolve(fileReader.result); // Here is the base64 string
    };
  });
};

const base64AudioFile = await blobToBase64(mediaBlobUrl);
sendToServer(file: base64AudioFile)

Then on my server essentially I did with ffmpeg

file = params['file']
decoded_file_string = Base64.decode64(file)
saveAsWavFileOnFileSystem(decoded_file_string)
ffmpeg -y -i path/to/saved_file.wav -vn -ar 44100 -ac 2 -b:a 192k  path/to/new_file.mp3

@renny-ren
Copy link

I'm facing the same issue and I have to use ffmpeg to convert the audio format manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants