ARTICLE AD BOX
I am attempting to use the Web Audio API to play a sine tone to a specific audio output device.
(If you're interested, the use case is to play a short 1750 Hz tone to an audio interface attached to a ham radio, which "opens" a repeater).
For that, I first use:
navigator.mediaDevices.enumerateDevices()to get a list of audio output interfaces and populate a dropdown with it.
Then, in a function attached to a "run" button, I use the currently selected deviceId as a constraint in:
navigator.mediaDevices.getUserMedia()to get that specific audio device's MediaStream.
After that, I:
Create an AudioContext instance. Create a MediaStreamDestinationNode on that audio context from the stream Create an OscillatorNode and connect its output to the destination.However, I run into a problem already at the second step.
It appears that (tested on Chrome 145.0.7632.117, macOS Tahoe 26.3), when looking at the track's label, the MediaStream's first and only track is always my MacBook's microphone instead of the speaker device that I selected. For that reason, I also do not hear any audio playing.
I created a minimal reproduction snippet that shows the issue.
You will need to open the Console to see the unexpected track label. You may also need to manually grant stacksnippets.net microphone and speaker permissions, because Chrome does not always prompt for them automatically.
