Output Sound To Audio Device

☆樱花仙子☆ 提交于 2019-12-12 03:36:11

问题


I'm trying to create a script that will trigger a sound effect when a hotkey is pressed, this might not seem too difficult, but I also want to be able to output it to a specific audio device, a virtual audio cable in my case.

I've looked around on the internet a bit and I saw many possible solutions, but none have worked out for me (yet). It appears that the normal SoundPlay function in AHK can not output to a specific audio device, but I'm also looking into other options, like playing the sound via a batch script with wmplayer or other media players, but I can't find a solutions that will let me output the sound to a specific audio devices...

So my question is, what's the best way to play sound to a specific non-default audio device (a virtual audio cable) which can be done inside a command prompt or inside autohotkey?


EDIT: I've found a solution, see answer below.


回答1:


So I managed to do what I was trying to accomplish. I'll tell you how I did it:

After some searching around on the internet I came across a C# library called IrrKlang. Using IrrKlang I made a little console app program which I can call by playsound soundfile.mp3 0, playsound is the the name of the .exe, the first parameter is the path to the soundfile from the location of the playsound.exe, and the last parameter is a number which is used to choose the audio device, which number this should be is still guess work but after some trial and error you can find the number of your virtual audio cable or other audio device.

For the people who come here in the future I've put my code up on github.




回答2:


Everything you need is here:

Lexikos's Vista Audio Control Functions

Note: SoundSet and SoundGet on AutoHotkey v1.1.10 and later support Vista and later natively. You don't need VA.ahk unless you want to use advanced functions not supported by SoundSet/SoundGet.

https://autohotkey.com/board/topic/21984-vista-audio-control-functions/

To change the default output device, you can script the Sound properties in cpanel:

Run, mmsys.cpl
WinWait, Sound
    ControlSend, SysListView321,{Down num}  ' num matches device position
    Sleep, 100
    ControlClick, &Set Default
    Sleep, 100
    ControlClick, OK
WinWaitClose, Sound

Hth,



来源:https://stackoverflow.com/questions/43225260/output-sound-to-audio-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!