Hack Forums
[.NET] Route audio to specific device? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Route audio to specific device? (/showthread.php?tid=5819243)



Route audio to specific device? - PolarisGang - Apr 1, 2018

Is there any decent way to route audio emitted from my application to a specific audio output device without having said device set as the default output device?

I am aware of software like CheVolume but I'm trying to rely as little as possible on other programs.


RE: Route audio to specific device? - SlowMehMo - Apr 3, 2018

This would be difficult to accomplish without a library or something to help you out.
try out naudio, there is good documentation apparently, i see what you mean tho it is hard to find some answers on google.


RE: Route audio to specific device? - PolarisGang - Apr 3, 2018

(Apr 3, 2018 02:43 AM)SlowMehMo Wrote:  This would be difficult to accomplish without a library or something to help you out.
try out naudio, there is good documentation apparently, i see what you mean tho it is hard to find some answers on google.

I'll have a look. It can obviously be done, I just lack knowledge about the subject. One would think there were already functions for this somewhere.


For anyone having similar issues you should be able to play sound files with specific audio devices with both NAudio(not looked up how) and Irrklang.
Example for Irrklang:
Code
'Get the list of installed sound devices.
dim sdl = new IrrKlang.ISoundDeviceList(IrrKlang.SoundDeviceListType.PlaybackDevice)

'Add each device to a combo box.
For i As Integer = 0 to sdl.DeviceCount
    comboBox1.Items.Add(sdl.getDeviceDescription(i) + "\n")
Next

'Place this code in your play sound event handler.
'Create a sound engine for the selected device (uses the ComboBox index to get device ID).
irrKlangEngine = new IrrKlang.ISoundEngine(IrrKlang.SoundOutputDriver.AutoDetect, _
                IrrKlang.SoundEngineOptionFlag.DefaultOptions, _
                sdl.getDeviceID(comboBox1.SelectedIndex))

'Play the selected file
playSelectedFile(fileName)

Now my new problem is figuring out how to use this with the SAPI speechLib...


RE: Route audio to specific device? - SlowMehMo - Apr 4, 2018

(Apr 3, 2018 03:56 PM)PolarisGang Wrote:  I'll have a look. It can obviously be done, I just lack knowledge about the subject. One would think there were already functions for this somewhere.


For anyone having similar issues you should be able to play sound files with specific audio devices with both NAudio(not looked up how) and Irrklang.
Example for Irrklang:
Code
'Get the list of installed sound devices.
dim sdl = new IrrKlang.ISoundDeviceList(IrrKlang.SoundDeviceListType.PlaybackDevice)

'Add each device to a combo box.
For i As Integer = 0 to sdl.DeviceCount
   comboBox1.Items.Add(sdl.getDeviceDescription(i) + "\n")
Next

'Place this code in your play sound event handler.
'Create a sound engine for the selected device (uses the ComboBox index to get device ID).
irrKlangEngine = new IrrKlang.ISoundEngine(IrrKlang.SoundOutputDriver.AutoDetect, _
               IrrKlang.SoundEngineOptionFlag.DefaultOptions, _
               sdl.getDeviceID(comboBox1.SelectedIndex))

'Play the selected file
playSelectedFile(fileName)

Now my new problem is figuring out how to use this with the SAPI speechLib...

Are you doing the Text to speech thing or the voice recognition? I researched this for a little while a few months ago wanting to make mic spammer but then stopped now you got me interested again.
it also popped into my mind you could use CaffeineAU TTSAutomate to save text as a MP3 and then play it,
but there has to be a better method that doesnt drop to disk. Maybe still worth taking a look at how they handled the speech 😧


RE: Route audio to specific device? - PolarisGang - Apr 6, 2018

(Apr 4, 2018 11:43 PM)SlowMehMo Wrote:  Are you doing the Text to speech thing or the voice recognition? I researched this for a little while a few months ago wanting to make mic spammer but then stopped now you got me interested again.
it also popped into my mind you could use CaffeineAU TTSAutomate to save text as a MP3 and then play it,
but there has to be a better method that doesnt drop to disk. Maybe still worth taking a look at how they handled the speech  😧

TTS ye. I'll take a look whenever I have free time.