Streaming audio files via NodeJS
With the raise of AI, we are seeing more and more applications that require server-side audio streaming capabilities. In this article, we will show you how to stream an audio file into an ODIN room using our NodeJS SDK.
Use cases
There are many use cases for audio streaming. Here are some examples:
- Talking with an Artificial Intelligence (AI) bot. You need to stream the audio from the user to the AI and the audio from the AI to the user.
- Playing music in a room.
- Playing a sound effect in a room.
Our NodeJS SDK is perfect for these use cases. It allows you to receive audio streams from users and send audio streams back into the room. You can transform the audio stream you receive from users into text with OpenAIs Whisper API and you can use AWS Polly to transform text into audio and send it back to the room.
In all of these use cases, you can concentrate on building the use-case while ODIN handles all that audio and networking stuff for you.
Example
This example takes an MP3 file and streams it into an ODIN room. It uses the following libraries:
Providing a UserData
object is not necessary but its good practice and allows you to identify your bot in the room.
The
user data object is a JSON object that is used by our Web client we use internally for testing. You can use it quickly
test if everything works fine. More info on the web client can be found here.
Next steps
If you can send audio, you might also be interested in receiving audio and eventually transcribing it into text for content moderation or AI interaction. We have an example for that too. You can find it here.
ODIN Bot SDK
This example is just a starting point. You can use it to build your own audio streaming application. We have built an ODIN Bot SDK in TypeScript built on top of the ODIN NodeJS SDK that you can use to build your own AI bots and provides simple interfaces to capture and send audio streams. We have published it as a separate NPM package. You can find it here.