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

ReadableStream or Readable from AudioContext #27

Open
noramass opened this issue Jul 25, 2023 · 3 comments
Open

ReadableStream or Readable from AudioContext #27

noramass opened this issue Jul 25, 2023 · 3 comments

Comments

@noramass
Copy link

noramass commented Jul 25, 2023

I want to stream the resulting audio post processing to discord for a sound bot.

So far i have not found a way to get binary data from the AudioContext object, raw, encoded or otherwise.
In the examples directory I couldn't find any examples of exporting the audio to a file or a stream and while debugging i couldn't find a method to do so either.
I tried using createMediaStreamDestination, like documented on MDN but that method doesn't seem to exist on AudioContext.

Can someone help me please?
I would love to use this module in my project.

@b-ma
Copy link
Collaborator

b-ma commented Jul 25, 2023

Hey,

createMediaStreamDestination is indeed not exposed / implemented (it is implemented on Rust side of the lib but it's not really sure what it means/imply in JS) and will probably not be anytime soon.

But for your use case, you could probably use an OfflineAudioContext which just render your graph offline and gives you an AudioBuffer. Then it should be quite straightforward to convert it to a .wav file (didn't try but for example https://www.npmjs.com/package/audiobuffer-to-wav)

If you think there should a more precise example, happy if you propose one or I can add one too, let me know

@noramass
Copy link
Author

Thank you for your quick response! While this solves my issue somewhat i run into a different issue now. the soundbot acts like a web radio in that it isn't really supposed to stop. music tracks are faded into each other in one continuous stream of music. using a single audiobuffer for it all isn't feasible for me. would it be possible to expose a ReadableSteam so i can process data in real time and not bloat memory? the discord bot is running in several servers at the same time too, acting as a broadcast and listeners can be added and removed at any point in time. could you give me an example for how i could achieve this? please excuse the terrible formatting i'm on a trip and writing this from my phone.

@b-ma
Copy link
Collaborator

b-ma commented Jul 30, 2023

Hum I see, the offline context is hardly a solution in that case indeed. I have made some little research and unfortunately the Stream interface is not implemented yet on the napi-rs side (cf. napi-rs/napi-rs#1483), so I don't really see what I could do on the library in the short term.

Maybe a possible solution for you would be to use an online context to do the audio processing (cross-fades etc.), and rely on an external solution such as Icecast to create the broadcast stream(s)? This would make your server architecture a bit more complex but it should probably work.

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

2 participants