samirkumardas / opus-to-pcm

Decode raw opus packet to PCM without using any external library in your browser.
Other
73 stars 15 forks source link

extract raw opus stream from existing ogg file #29

Open jw-redpanda opened 3 years ago

jw-redpanda commented 3 years ago

First of all, thanks for your excellent work :> The server.js example works as expected and the sound can be played in the chrome browser.

I tried out my own ogg/opus file and split it into chunks using NNNN.txt format but they cannot be played normally. I guess it may be due to the fact that server.js expects to receive raw OPUS data without ogg header.

My question is... how can I extract the raw OPUS stream from an ogg file? I tried out ffmpeg and opusenc with no luck since they all convert audio in opus with ogg header.

Would you please advise the tool to extract raw stream? Any suggestion?

samirkumardas commented 3 years ago

If you have already an Opus packet with the Ogg header, you don't need to use this library. You can convert them into PCM by calling the function decodeAudioData directly.

In our case, we got bare opus packet using the libopus encoder https://opus-codec.org/downloads/

jw-redpanda commented 3 years ago

Thanks samirkumardas for your kind reply.

In fact, I am interested in using your approach to stream a very large ogg file by chunks from node server to the chrome browser. However, decodeAudioData expects complete binary data of an ogg file, which takes some time to begin playing since the file is large, especially when the Internet connection is slow.

BTW, I am a newbie in web audio, can you tell me what is OCM?

samirkumardas commented 3 years ago

Sorry, it was a typo. I meant to say PCM :)

In our case, we would convert from PCM into Opus. Then at the browser end, we received it over WebSocket and used this library to get the PCM stream back. Using WebAudio API, you can play PCM data.