Project Complexity: ★★★☆☆
Want to liven up your virtual Space with some MP3s played by a robot? Within 30 minutes, you can make that happen. The DJ Bot you'll have created by the end of this guide will have the human users of your application dancing all night long.
In this guide, you will learn how to:
If you already have a High Fidelity Developer Account, you can jump straight to the next step.
Before your app can make use of the Spatial Audio API, you'll need a High Fidelity Developer Account. Sign up for an account or log in here.
If you already have an App and Space for your DJ Bot, you can jump straight to the next step.
To authenticate our DJ Bot with your Space, you'll first need to create an App and a Space. To do that:
Do not share the data you see on this page. It allows users to make authorized connections to your High Fidelity Spatial Audio Server.
To complete this guide, you will need to install the following software on your computer:
Next, let's create a skeleton version of a NodeJS project we'll use for development:
Create a new folder on your local disk that you'll use for development, such as C:\code\hifi-dj-bot\
. Then, install the JavaScript (NodeJS) version of the High Fidelity Spatial Audio Client Library by performing the following actions:
C:\code\hifi-dj-bot\
.cd
into that development directory.npm init
to initialize a new NodeJS project, inputting data as prompted. The data you input isn't important for the purposes of this guide.npm install hifi-spatial-audio
To make our lives easier later, we're now going to install all of the NodeJS dependencies used for this DJ Bot project. We'll make use of these dependencies in the next steps.
audio-decode
by typing npm i audio-decode
and pressing enter.
audio-decode
, you may see some warnings or errors in your console window. These warnings and errors are benign, and you can safely continue.audio-format
by typing npm i audio-format
and pressing enter.
MediaStream
object that we'll send up to the High Fidelity Spatial Audio Server.pcm-convert
by typing npm i pcm-convert
and pressing enter.
MediaStream
object that we'll send up to the High Fidelity Spatial Audio Server.yargs
by typing npm i yargs
and pressing enter.
jose
by typing npm i jose
and pressing enter.
wrtc
by typing npm i wrtc
and pressing enter.
MediaStream
object that we'll send up to the High Fidelity Spatial Audio Server.npm i wrtc
and also see SKIPPING OPTIONAL DEPENDENCY
, do not fret! The wrtc
package has an optional dependency that may not build on your system. These errors are benign, and you may ignore them.Inside your development directory, create a new file called index.js
. This is where we'll write our code.
Now that you have your development environment set up, it's time to write some code!
Here's the entire contents of a nearly-completed index.js
DJ Bot. Copy this code into your index.js
file.
We say "nearly-completed" above because you have to fill in your APP_ID
, SPACE_ID
, APP_SECRET
, and USER_ID
in the code. You gained access to this information in the "Create an App and Space" step above. For reference, you can find these pieces of information in the High Fidelity Audio API Developer Console.
After filling in the above information, in the PowerShell or Terminal window you've been using, type node index.js --audio <path to local audio file>
and press enter to execute the code. You can get a list of all command-line options by typing node index.js -h
and pressing enter.
If the DJ Bot is running successfully, you won't hear anything, but you will see DJ Bot connected. Let's DANCE!
in your PowerShell or Terminal window. If you specified the SPACE_ID that corresponds to the JWT you created for your Simple Web app, you will hear audio after you start your DJ Bot then open your Simple Web app and connect to that space.
In this guide, you learned how to create a groovy DJ Bot for use in your High Fidelity Spatial Audio Space. Your DJ Bot takes an MP3 file from your local disk and broadcasts the audio from that file into your Space! 🎶
You learned that you can use the "Simple Web App" guide to build a Web app from which you can listen to your DJ Bot. Click here to go to that guide.
For detailed technical information about the High Fidelity Spatial Audio Client API, visit the API documentation.
If you have any questions or comments, please reach out to support@highfidelity.com.