Overview
We offer ODIN, a high-quality cross-platform immersive voice SDK that includes state-of-the-art noise suppression technologies.
Our Web SDK includes fallback code for WebRTC and is compatible with most browsers. While it can also be used in NodeJS, it may not be as performant as our native NodeJS SDK, which is designed for advanced use cases and bots.
The NodeJS SDK is currently in beta. This means that the API is not final and may change from version to version, and it may not be ready for large-scale production use. If you encounter any issues, please let us know on our Discord server.
Although we strive to keep the API as similar as possible between our SDKs, there are some differences. Since wrapping objects in JavaScript and TypeScript is easier than in C/C++, we only use objects where necessary in our native SDK. For instance, the WebSDK provides an OdinPeer object that encapsulates various methods and properties. However, for NodeJS use cases, you usually only need a peerId and mediaId, so we decided not to overcomplicate things. Of course, you can always create your own wrapper if needed.
The main difference between the two SDKs is that the NodeJS version allows you to access raw audio data from the ODIN server, which enables you to record or stream audio to the room. While the WebSDK has similar capabilities, it relies on Web Audio, which is not available in NodeJS. Rather than creating a complex polyfill, we found it easier and faster to wrap the ODIN native SDK into NodeJS bindings.
By providing two separate libraries, we can optimize each one for its respective platform and use cases.
ODIN is our cross-platform immersive voice SDK with best-in-class quality and noise suppression technologies.
Source Code
The NodeJS SDK is developed in C/C++ using Node API and is open source. Check out the source in our public NPM repository.
Installation
Install the web SDK via npm
in your project like this:
Interoperability
The ODIN web SDK is fully compatible with our other client SDKs, so you can easily communicate between your NodeJS script and other clients—even Unity or Unreal Engine clients.
However, it's important to understand that you cannot combine the WebSDK and the NodeJS SDK in the same NodeJS project.
You either have @4players/odin-nodejs
or @4players/odin
in your package.json
file, but not both.
Platform support
As the ODIN NodeJS SDK is a native module, it requires native binaries to be built for your platform. We currently provide prebuilt binaries for these platforms:
- Windows (x64)
- macOS (x64 and ARM)
- Linux (x64)
If you deploy your application to a different platform, npm install
will try to build the library from source. This
requires a working C/C++ compiler and the necessary build tools to be installed on your system. You can find more info
on that topic in the node-gyp documentation.
Event Handling
The ODIN server will automatically notify you about relevant updates, and the ODIN NodeJS SDK uses the JavaScript EventTarget API to dispatch custom events based on the OdinEvents interface. Use any of the provided addEventListener methods to set up a function that will be called whenever the specified event is delivered to the target.
These events are available:
OdinEventsUse them like shown in this example:
Using Media objects
ODIN works with the concept of media objects that are attached to a room. A media is either remote (i.e., connected to the mic of someone else’s device) or a local media, which is linked to your own microphone or other input device.
After joining a room, you can create a media (linked to your local input device) and add it to the room. After joining a room, you are just a listener in the room, you don't send anything to it (i.e., you are muted).
Receiving audio data
Once the script has joined a room, it receives events that you add handlers for. If you want to get access to audio
data, you'll need to add an event handler for AudioDataReceived. The
data
property of the event
contains the audio samples in 16-bit format or 32-bit floats (-1 to 1):
Sending audio data
If you want your bot to send audio into the room (i.e., text to speech or music and other sounds), you need to attach a media to that room:
Examples
We have prepared a couple of examples to get you started with the ODIN NodeJS SDK. You can find them in our SDK in the
tests
folder. After installing the NodeJS SDK, check out this folder: node_modules/@4players/odin-nodejs/tests
.
You'll find one example on how to record audio and send it to OpenAI's whisper module for transcription and
another sample that shows you how to send data into the channel. Examples are also provided for sending text
messages when users join the room.