将声音输出到音频设备 [英] Output Sound To Audio Device

查看:90
本文介绍了将声音输出到音频设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个脚本,该脚本将在按下热键时触发声音效果,这似乎不太困难,但是我还希望能够将其输出到特定的音频设备(虚拟音频电缆)就我而言.

我已经在互联网上四处张望,看到了许多可能的解决方案,但还没有一个对我有帮助(至今).看来AHK中的常规SoundPlay功能无法输出到特定的音频设备,但是我也在寻找其他选项,例如使用wmplayer或其他媒体播放器通过批处理脚本播放声音,但是我找不到让我将声音输出到特定音频设备的解决方案...

所以我的问题是,在特定的非默认音频设备(虚拟音频电缆)上播放声音的最佳方法是什么?可以在命令提示符下或在自动热键中进行播放? >


我找到了一种解决方案,请参见下面的答案.

解决方案

所以我设法完成了自己想做的事情.我会告诉你我是怎么做到的:

在Internet上进行了一些搜索之后,我遇到了一个名为IrrKlang .使用IrrKlang,我制作了一个小的控制台应用程序,可以通过playsound soundfile.mp3 0调用,playsound是.exe的名称,第一个参数是从playsound.exe位置到声音文件的路径,最后一个参数是用于选择音频设备的数字,应该仍然可以猜测该数字,但是经过反复试验后,您可以找到虚拟音频电缆或其他音频设备的数字.

对于将来来这里的人们,我已经将代码放在 github 上.

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.

解决方案

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.

这篇关于将声音输出到音频设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆