How I can know if I have headphones connected to my computer? HTML5 + JavaScript

前端 未结 2 1616
不知归路
不知归路 2021-02-06 18:41

How I can know if I have headphones connected to my computer? My goal is to get it using HTML5 + JavaScript.

On the next page shows all audio output devices, but there i

相关标签:
2条回答
  • 2021-02-06 18:58

    As of today (2019 march) there is no realiable, cross-browser built-in tool to detect whether a user has headphones plugged in. While you theoretically can get audio output destination device and test it for phrases like headset, earphones etc, in a typical case it rather provides you with driver's name, which usually doesn't change when user plugs his earphones in. The usually part makes this approach useless.

    0 讨论(0)
  • 2021-02-06 19:10

    There is no way using any existing API, but one way could be to send a sound out while checking if the microphone picks it up.

    This would be a real test for echo, you could use some "welcome" sound and some FFT code to "parse" microphone input and see if the sound you are sending is re-entering the microphone. However it would require quite some fine tuning to be reliable, and will still not catch people with low volume on the speakers or catch people with too loud headphones .. even if, in that case, since they are producing echo, catching them is probably the right thing to do.

    I can't remember which conferencing software was actually doing this setup step emitting a melody and checking the feedback (maybe it was Skype early versions?), but it's doable in modern browsers.

    0 讨论(0)
提交回复
热议问题