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

[Help] Data stored in audio file doesn't playback #46

Open
shyamal890 opened this issue May 18, 2024 · 0 comments
Open

[Help] Data stored in audio file doesn't playback #46

shyamal890 opened this issue May 18, 2024 · 0 comments

Comments

@shyamal890
Copy link

shyamal890 commented May 18, 2024

I am trying to utilize this library to:

  1. Record audio
  2. Play the audio locally before sending data to the server
  3. Send audio file to the server

Here's the current code:

In service

startRecording = ()=> {
        try {
            return VoiceRecorder.requestAudioRecordingPermission().then((result: GenericResponse) => {
                if (result.value) {
                    return VoiceRecorder.startRecording()
                } else {
                    return Promise.reject('Permission denied');
                }
            })
          } catch (error) {
            console.log(error);
            return Promise.reject(error);
        }
    }

stopRecording = async () => {
        console.log("stopRecording");
        let result = await VoiceRecorder.stopRecording();

        let blob = base64StringToBlob(result.value.recordDataBase64, result.value.mimeType);
        let data_text = await blob.text();
        let extension = mime.getExtension(result.value.mimeType);
        let write_result = await Filesystem.writeFile({
            path: `temp.${extension}`,
            data: data_text,
            directory: Directory.External,
            encoding: Encoding.UTF8,
        });
        let uri = write_result.uri;

        return uri;
    }

At this point I tested the locally stored file temp.aac. Sent the file to PC and tried to playback the audio but audio player gives corrupted or codec error (note tried multiple audio players). While .aac file downloaded from the internet works absolutely fine.

What have I tried till now:

  1. Tried storing data as shown above
  2. Tried forcing the extension to be .aac instead of .adts that mime.getExtension suggests
  3. Tried storing base64 data directly
  4. Tried storing data:${result.value.mimeType};base64,${result.value.recordDataBase64}

None of these have worked. Any suggestions would be appreciated.

PS: Maybe we need to encode the raw data before storing it to a file. Ref - https://stackoverflow.com/a/18970406/3955513

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

1 participant