RELIABLE way to identify if an audio device can record audio?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
OliverK
Posts: 28
Joined: 08 Mar 2023, 11:55

RELIABLE way to identify if an audio device can record audio?

08 Mar 2023, 12:59

Hello,

Short intro: I've been using Autohotkey for years here and then.. back with more interest since V2. Really great and enjoyable.

Short question: Is there a RELIABLE way to determine if an audio device/component can RECORD something (aka "capture audio").

I've read a lot.. but it all boils down that there's no sure way to do so. I've used the "soundcard analysis script" from
https://www.autohotkey.com/docs/v2/lib/Sound.htm#device
but the results have been even more confusing.

Sometimes, microphones have a "Capture" label for their respective component name (very good - and language independent as it seems, worked on a german Windows), sometimes other mics don't have any component name at all ( ...uhhh..),
sometimes there's a component name labeled "Microphone" but not "Capture" (... okay.. so.. different labels possible?), sometimes whatever microphone means in the language of the Windows installation ( .. oh my..*sigh*),
sometimes there's a component name labeled "Microphone" for the speaker (!) component of the microphone (headphone jack at the mic to hear your voice), so the corresponding row in the soundcard analyis GUI says something like
"component: Microphone" -"Device: Speaker - Blue Yeti" , the "real" microphone (identified via muting and volume settings, it was the "real" one) has no component name at all ( *heavy sigh* ) but the device reads "Device: Microphone - Blue Yeti" ....

Yes, it's very confusing. No way I could boil that down to a logic which identifies and filters the audio devices for their recording capabilities.

Is there NO method to "ask" a device and its components "are you a record-capable component of this device" ?

Thanks!
OliverK
Posts: 28
Joined: 08 Mar 2023, 11:55

Re: RELIABLE way to identify if an audio device can record audio?

17 Mar 2023, 18:40

Well.. I'll give the answer myself, maybe it'll be useful some day..

Short version: I converted parts of the "old" Vista Audio Control library to AHK 2.0
https://www.autohotkey.com/board/topic/21984-vista-audio-control-functions/
because using this library you can identify audio devices/components with a "capture" data flow (mics for example)
and I used a subset of the functions and wrote an additional one for my needs.

It's not that easy (ComObjects, DllCalls and quite a stuff sourrounding this stuff have changed with AHK V2) and there doesn't seem to be much interest, so no full explanation here, sorry (would take a while).

But as I said.. look out for the Vista Audio Control library, study it and use the "right" parts...
deluxghost
Posts: 1
Joined: 16 Feb 2023, 05:17

Re: RELIABLE way to identify if an audio device can record audio?

10 Apr 2023, 02:05

I also want to port VA.ahk to v2, even if parts of it, but I just cannot figured it out. Could you share some code or examples?
OliverK
Posts: 28
Joined: 08 Mar 2023, 11:55

Re: RELIABLE way to identify if an audio device can record audio?

11 Apr 2023, 15:57

deluxghost wrote:
10 Apr 2023, 02:05
I also want to port VA.ahk to v2, even if parts of it, but I just cannot figured it out. Could you share some code or examples?
I could, but I've only ported the parts which I needed.. mainly those which deal with the "flow" of the data (which is needed to determine if a device is capable of recording) and all the functions which are needed to set everything up (like enumbering devices) in the first place.

I won't promise they are ported "right" and bug free.

They work for me..

What do you need?

I can post the whole bunch of ported VA - code which I've done so far, but as I said, I'm not too sure of the quality (I'm not to sure I use everything of the ported code, so there may very well be even crash-prone sections in it which I've never discovered because they were never used in the first place).
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: RELIABLE way to identify if an audio device can record audio?

11 Apr 2023, 20:18

OliverK wrote:
17 Mar 2023, 18:40
Well.. I'll give the answer myself, maybe it'll be useful some day..

Short version: I converted parts of the "old" Vista Audio Control library to AHK 2.0
https://www.autohotkey.com/board/topic/21984-vista-audio-control-functions/
because using this library you can identify audio devices/components with a "capture" data flow (mics for example)
and I used a subset of the functions and wrote an additional one for my needs.

It's not that easy (ComObjects, DllCalls and quite a stuff sourrounding this stuff have changed with AHK V2) and there doesn't seem to be much interest, so no full explanation here, sorry (would take a while).

But as I said.. look out for the Vista Audio Control library, study it and use the "right" parts...
i was on a similar question just few days ago
viewtopic.php?f=82&t=115832
and same as deluxghost i am nit that skilled, to transport code out of ahkv1 into v2

i searched a easy way to toggle MicMute with a hotkey , and done cycles and ideas wiht mikeyww
OliverK
Posts: 28
Joined: 08 Mar 2023, 11:55

Re: RELIABLE way to identify if an audio device can record audio?

11 Apr 2023, 22:28

Tobgun1 wrote:
11 Apr 2023, 20:18


i searched a easy way to toggle MicMute with a hotkey , and done cycles and ideas wiht mikeyww
Funny.. I created an AHK script (with optional GUI) to do just that.. it was the reason I had to port the VA code in the first place.

Maybe I'll just post the whole code here.. it's gotten quite big for such a simple task and consists of several files.
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: RELIABLE way to identify if an audio device can record audio?

11 Apr 2023, 23:06

OliverK wrote:
11 Apr 2023, 22:28
Tobgun1 wrote:
11 Apr 2023, 20:18


i searched a easy way to toggle MicMute with a hotkey , and done cycles and ideas wiht mikeyww
Funny.. I created an AHK script (with optional GUI) to do just that.. it was the reason I had to port the VA code in the first place.

Maybe I'll just post the whole code here.. it's gotten quite big for such a simple task and consists of several files.

You should. It might be good and searched In the future. And probably some professional can shorten it.

My problem was sound mute was a one liner and mic mute was nearly impossible 🙈 specially if you got multiple devices like a plug in headset or plug in microphone you might not use always...

So yeah lemme see it 😅👍
OliverK
Posts: 28
Joined: 08 Mar 2023, 11:55

Re: RELIABLE way to identify if an audio device can record audio?

12 Apr 2023, 00:09

Tobgun1 wrote:
11 Apr 2023, 23:06
My problem was sound mute was a one liner and mic mute was nearly impossible 🙈 specially if you got multiple devices like a plug in headset or plug in microphone you might not use always...
Yeah.. that's one of the problems.. audio device handling is quite a complex topic.
Tobgun1 wrote:
11 Apr 2023, 23:06

So yeah lemme see it 😅👍
I'll see what I can do, the project consists of several files, even multiple PDF files for documentation which can be shown via the integrated help function... there's even a "non-gui-mode" and several startup parameters and stuff.... I'll have to see how I can upload all this stuff here (or I'll have to link to a file storage service, a kind of git hub service or something like that).
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: RELIABLE way to identify if an audio device can record audio?

12 Apr 2023, 05:23

Ok ok then, honestly I did not thought it is such a big thing... I just could tell you if you would figure out a "new" solution it would be a thing.

Even a port of the VA library into AHKv2 could be a pleasure for the "community"

I am not able to do such stuff otherwise I might give it a think about it. 😅

Well I like AHK a lot but still incredible complicated for me even while I started to understand that language now...
OliverK
Posts: 28
Joined: 08 Mar 2023, 11:55

Re: RELIABLE way to identify if an audio device can record audio?

13 Apr 2023, 00:00

Tobgun1 wrote:
12 Apr 2023, 05:23
Ok ok then, honestly I did not thought it is such a big thing... I just could tell you if you would figure out a "new" solution it would be a thing.
I've looked into source code of other projects with similar objectives (managing/muting audio devices), like "Microsoft PowerToys" (which has a mic mute function and its source code is freely available) and .. it does essentially the same.
So it seems there's no other way if an "official" tool implemented it in the same way.
Tobgun1 wrote:
12 Apr 2023, 05:23
I am not able to do such stuff otherwise I might give it a think about it. 😅

Well I like AHK a lot but still incredible complicated for me even while I started to understand that language now...
The problem is not AHK itself in my opinion. The problem is, that you have to dive in Dll - Calls (via AHKs DllCall - function) and the like, meaning you're calling functions from different Window APIs.. where you have to convert variables for calls into different data types back and forth, dealing
with pointers, even releasing of memory sometimes and and and..

This is nothing which is specific for AHK, stuff like this gets nasty in every language which is not the language with which the APIs have been coded (C++ mostly), Visual Basic calls to DLL stuff don't look much friendlier for example.

I'll have to look up the project files and maybe have a look into the code again before releasing it, so it will take some days maybe.
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: RELIABLE way to identify if an audio device can record audio?

13 Apr 2023, 04:56

Well your choice , otherwise throw it. There is a solution you get referred here... use another program 😂🤷🏻‍♂️
Or use VA library from 2010 🙈🤷🏻‍♂️

I want to try a workaround version with my basic skills.
Something like a common possible solution.

Like mute device 1-20 with error throws of you unplug a device between those numbers.
OliverK
Posts: 28
Joined: 08 Mar 2023, 11:55

Re: RELIABLE way to identify if an audio device can record audio?

14 Apr 2023, 15:34

Here it is.. the VA library with the converted code is located in VA_V2.ahk (only partially converted),
MuteAudioDevices.ahk is "the main file".

Expand everything in a folder and execute MuteAudioDevices.ahk, doc file can be found in en_Manual_MuteAudioDevices.pdf (english version)
or opened via the help menu of the GUI.
Attachments
MuteAudioDevices.zip
ZIP-file containing the code itself, help files (pdf files) etc.
(459.24 KiB) Downloaded 73 times
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: RELIABLE way to identify if an audio device can record audio?

14 Apr 2023, 17:15

OliverK wrote:
14 Apr 2023, 15:34
Here it is.. the VA library with the converted code is located in VA_V2.ahk (only partially converted),
MuteAudioDevices.ahk is "the main file".

Expand everything in a folder and execute MuteAudioDevices.ahk, doc file can be found in en_Manual_MuteAudioDevices.pdf (english version)
or opened via the help menu of the GUI.
Hey cool thank you 😊👍
My last few script issues did not worked good. So I stopped for some days to relax... work also.

I give it a look next few days 😊👍 thanks for sharing.
OliverK
Posts: 28
Joined: 08 Mar 2023, 11:55

Re: RELIABLE way to identify if an audio device can record audio?

14 Apr 2023, 23:54

Note: to just browse capture capable audio devices, toggle the "only capture devices" in the settings menu, see attachment.
MuteAudioDevices.png
MuteAudioDevices.png (66.53 KiB) Viewed 1261 times
The code itself is far from perfect: for example, if you don't toggle the "ony capture devices" button it doesn't use the VA library but the built-in sound device functions of AHK,
because this part (where all audio devices were listed and could - and still can - be muted with their recording AND playback functionality) was completed earlier, I had to resort to the VA port because I didn't see a way
to identify capture capable devices with AHK functionality alone.... of course I could have used the VA library throughout the code if I would have known this before.
SandyClams
Posts: 63
Joined: 02 Jul 2020, 11:55

Re: RELIABLE way to identify if an audio device can record audio?

24 Apr 2023, 09:42

you guys are amazing. I had a similar problem to these problems myself within the past couple of days. I also found the VA library, and I also considered converting it or partially converting it for my needs, but up to now I've been too lazy to really dig into it. Instead I found a NirSoft tool that mostly does what I need, namely enumerating devices and switching devices. Now I just have some hacky thing in v2 that calls into the NirSoft app when I need it, and it works. This may be a reasonable solution for someone else in my position, who isn't really in a hurry to mess with that API....
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: RELIABLE way to identify if an audio device can record audio?

24 Apr 2023, 09:44

SandyClams wrote:
24 Apr 2023, 09:42
you guys are amazing. I had a similar problem to these problems myself within the past couple of days. I also found the VA library, and I also considered converting it or partially converting it for my needs, but up to now I've been too lazy to really dig into it. Instead I found a NirSoft tool that mostly does what I need, namely enumerating devices and switching devices. Now I just have some hacky thing in v2 that calls into the NirSoft app when I need it, and it works. This may be a reasonable solution for someone else in my position, who isn't really in a hurry to mess with that API....
Throw it online then 😊
SandyClams
Posts: 63
Joined: 02 Jul 2020, 11:55

Re: RELIABLE way to identify if an audio device can record audio?

24 Apr 2023, 10:00

@Tobgun1, my thing just toggles between the two connected audio devices that I use personally, those being my TV out and my headphone out. It doesn't seem particularly related to what's being attempted in this thread, even though the underlying tool is. It's also implemented kinda weird, I'll prob do some more work trying to make it palatable to another human before I encourage anyone else to use it. Though if you're absolutely dying for it feel free to let me know, I have no idea how inspired I will ever be to keep up with the thing
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: RELIABLE way to identify if an audio device can record audio?

24 Apr 2023, 10:40

@SandyClams yeah sure totaly not witty the effort BUT
It is always someone searching it, and maybe not asking for it or searching a solution .
So everything online can be get googled and can be usefull.

So I recommend always to share stuff and safe it online so google can find it.

But if cuse I do not know how much work it is and how much solution it might be.

So your choice 😬👍
OliverK
Posts: 28
Joined: 08 Mar 2023, 11:55

Re: RELIABLE way to identify if an audio device can record audio?

24 Apr 2023, 15:29

SandyClams wrote:
24 Apr 2023, 09:42
you guys are amazing. I had a similar problem to these problems myself within the past couple of days. I also found the VA library, and I also considered converting it or partially converting it for my needs, but up to now I've been too lazy to really dig into it. Instead I found a NirSoft tool that mostly does what I need, namely enumerating devices and switching devices. Now I just have some hacky thing in v2 that calls into the NirSoft app when I need it, and it works. This may be a reasonable solution for someone else in my position, who isn't really in a hurry to mess with that API....
Yes, I stumbled over the NirSoft tool also .. but I found the VA library more .. elegant in a way, because you don't need another component to rely on.. just AutoHotkey.

I guess at the end of the day the NirSoft tool just uses the same Windows API anyway.. the fact that the NirSoft tool ("SoundVolumeView v2.41" from nirsoft.net I guess) works beginning with Windows Vista is a hint in that direction.. VA library means "Vista Audio library", because the API is around since Windows Vista.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 30 guests