TooTallNate / node-speaker

Output PCM audio data to the speakers
648 stars 145 forks source link

Add support for selecting output audio device in Windows (win32 module) #154

Closed nacgarg closed 2 years ago

nacgarg commented 3 years ago

Previously, the win32 output module would always use the default output device (WAVE_MAPPER). To support selecting non-default output devices, this PR will enumerate all output devices and pick the device with the same name as ao->device. The name comes from the szPname field in WAVEOUTCAPS which is limited to 32 characters (including null sentinel). This means that to select an audio device such as Speakers (High Definition Audio Device), ao->device must be truncated to the first 31 characters of that followed by the null byte.

daytonellwanger commented 2 years ago

@LinusU @nacgarg could we get a review on this? There are many uses where the default device isn't the appropriate device to use and the user needs the ability to select the desired output device. Not having the ability to change the output device makes this package unusable for these use cases.

daytonellwanger commented 2 years ago

@LinusU is there someone else we should tag to take a look at this change? Are changes like this still being accepted to this project? Or should I create and publish a fork if I need this behavior?

nacgarg commented 2 years ago

@daytonellwanger Wow, I just realized it's been over a year without any response from the maintainers, so I appreciate you bumping this PR. I'd welcome any feedback about this change and will fix any issues that come up so that we can get this merged in. In the meantime, I've been using my fork with npm by adding "speaker": "https://github.com/nacgarg/node-speaker" to package.json.

LinusU commented 2 years ago

Sorry for the very long delay here. I cannot personally test this, but I will merge and release this since it seems that multiple people have reacted positively to this PR, and since the code looks straight forward enough.

LinusU commented 2 years ago

Released as 🚢 0.5.4 / 2022-03-16!

Again, sorry for the delay 🙏

daytonellwanger commented 2 years ago

Thanks @LinusU ! Much appreciated 🙏