The High Fidelity Audio Client Library allows developers to integrate High Fidelity's spatial audio technology into their projects.
npm install hifi-spatial-audio
Import the latest version of the main library with:
<script src="https://hifi-spatial-audio-api.s3-us-west-2.amazonaws.com/releases/latest/HighFidelityAudio-latest.js"></script>
API documentation is available at docs.highfidelity.com.
You'll find a bunch of examples that make use of this API in the Spatial-Audio-API-Examples GitHub Repository.
Walkthrough guides of sample applications written in plain Web JavaScript and written in NodeJS are available at highfidelity.com/api/guides.
Here's a super basic version of how to use the High Fidelity Spatial Audio Client Library in the Web JavaScript context:
<script src="https://hifi-spatial-audio-api.s3-us-west-2.amazonaws.com/releases/latest/HighFidelityAudio-latest.js"></script>
<script>
// Set up the initial data for our user.
// They'll be standing at the origin, facing "forward".
let initialHiFiAudioAPIData = new HighFidelityAudio.HiFiAudioAPIData({
position: new HighFidelityAudio.Point3D({ "x": 0, "y": 0, "z": 0 }),
orientationEuler: new HighFidelityAudio.OrientationEuler3D({ "pitch": 0, "yaw": 0, "roll": 0 })
});
// Set up our `HiFiCommunicator` object, supplying our media stream and initial user data.
let hifiCommunicator = new HighFidelityAudio.HiFiCommunicator({
initialHiFiAudioAPIData: initialHiFiAudioAPIData
});
// `audioMediaStream` is obtained from a separate `getUserMedia()` call.
await hifiCommunicator.setInputAudioMediaStream(audioMediaStream);
// Connect to the High Fidelity Audio Spatial API Server by supplying your own JWT here.
// Follow this guide to get a JWT: https://www.highfidelity.com/api/guides/misc/getAJWT
// If you don't need a guide, obtain JWT credentials after signing up for a developer account at https://account.highfidelity.com/dev/account
const HIFI_AUDIO_JWT = "";
try {
await hifiCommunicator.connectToHiFiAudioAPIServer(HIFI_AUDIO_JWT);
} catch (e) {
console.error(`Error connecting to High Fidelity:\n${e}`);
return;
}
</script>