chrisguttandin / standardized-audio-context

A cross-browser wrapper for the Web Audio API which aims to closely follow the standard.
MIT License
679 stars 33 forks source link

How to choose the output device? #999

Open aaronvg opened 1 year ago

aaronvg commented 1 year ago

Chromium seems to have added support to choose the output device (see https://github.com/WebAudio/web-audio-api/pull/2498)

Are there any plans to add setSinkId to this library?

Could I just cast the AudioContext object from this library into the native one and call that method? Or maybe the other way around -- cast a native AudioContext to the standardized one? Or what's the best way of accessing the native AudioContext?

chrisguttandin commented 1 year ago

Hi @aaronvg,

thanks for creating this issue. My current thinking is that it could probably be implemented in a standards compliant way with very minimal effort.

audioContext.sinkId would always return '' since that is the default. And any call to audioContext.sinkId() would throw a NotSupportedError in those browsers that don't implement it.

The spec also includes a step to check the 'speaker-selection' permission but this seems to be in no browser so far.

Does that sound about right?

baparham commented 1 year ago

I've got my eyes on this one, since I'd love to be able to "natively" choose the output device in higher level libraries like Tone.js without needing to go through extra steps like outlined in https://github.com/Tonejs/Tone.js/issues/877

I would expect audioContext.sinkId to return the currently assigned sinkId which could be '' if you haven't explicitly set it via audioContext.setSinkId(...) right?