npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rtc-spatial

v0.0.1

Published

Library to spatialize audio signals for audio and video real time communications. The library makes use of the exising StereoPanner audio APIs in most of the browsers.

Downloads

1

Readme

RTC SPATIAL

Library to spatialize audio signals for audio and video real time communications. The library makes use of the exising StereoPanner audio APIs in most of the browsers.

To learn more about audio spatialization you can read this Unreal Engine document: xxx

To learn more about the SterePannerl you can check the MDN documentation: xxx

It has been only tested with Chrome but should work in other browsers too.

Install

The library can be installed as an npm package dependency in your project:

npm install rtc-spatial

How to spatialize audio streams

There are two ways you can use this library, the automatic mode provides a very easy way to integrate it without having to modify the application and the manual mode provides a more flexible and efficient way to do it.

The automatic mode detects automatically the audio and video elements in the page and spatialize their attached streams when their position changes.

The manual mode provides an API to map a specific audio stream to a spatialized version of it and provides the panner associated to that stream so that the application can control the panning based on the position of the elements or other application logic.

Automatic mode

In automatic mode there are just two simple start() and stop() APIs. The start API has some parameters to configure the association between audio and video elements for applications that use separated elements for a single participant. For the applications using a single video element per participant it should work out of the box.

start(options)

Options:

  • audioMapper: (audioElement): string Provide a function to extract the participantId corresponding to a specific audio element in the DOM. For example if the application is using the participantId as part of the element ID that can be a way to do the mapping.
  • videoMapper: (videoElement): string Provide a function to extract the participantId corresponding to a specific video element in the DOM. For example if the application is using the participantId as part of the element ID that can be a way to do the mapping.
start({ 
    audioMapper: (audio) => audio.id.split('-')[1],
    videoMapper: (video) => video.id.split('-')[1],
})

Manual mode

In manual mode there is a single simple API exposed that is spatialize(). In this mode the library provides a very tiny wrapper that is around 10 lines of code so you can consider copying the code instead of importing the library.

const { stream, panner } = spatialize(stream)

The panner returned is a standard Web panner with a value betwen -1 and 1.

Additional considerations

Echo cancellation is only enabled for the original audio streams from a RTCPeerConnection and not any other audio stream played back in the browser like the spatialized streams in this case. So in case the user is not using headphones it is very likely to introduce echo in the conversation when using spatialization and it is recommended to disable spatialization in that case. This can be workarounded with some tricks if really needed but another option is to wait for a new version of Chrome that should solve this limitation soon.

Most of bluetooth headphones don't support stereo mode for audio playback while using them to acapture audio from the microphone, so those users won't notice the effect of spatialization.