Jump to content

Retrieve the actual sound level


xMatz
 Share

Recommended Posts

Hey! Im creating a script that requires to check if the sound volume is greather than a value. I mean, if a sound that is played, is > 50% of the green bar line in the audio mixer, then it will do something, But i don't know if there's a way to retrieve or get the sound of that windows mixer. I hope that ive expressed correctly.

Link to comment
Share on other sites

17 minutes ago, xMatz said:

I hope that ive expressed correctly

Not really to be honest.  You do not give us much info nor code that you have tried.  What about starting by showing us that windows mixer with the au3info tool of some controls.  You can also look at using the interface MMDevice.  Then again, there is UIAutomation that could be help also.  There is multiple solutions but hard to say without a more precise view of what your target is... 

Edited by Nine
Link to comment
Share on other sites

Link to comment
Share on other sites

I do not believe you can read directly those controls to get volume level.  My best guess at the moment is to use the interface MMDevice.  Look for it in site, I know there is a few examples how to use the interface.  But it is not obvious unless you have a large experience of using COM interfaces.

Link to comment
Share on other sites

the prominent approach in AutoIt these days to address sound-related tasks is using the BASS UDF. it is much more powerful then its homepage description, but you'll have to put in the time and effort to implement for your specific requirement.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

1 hour ago, xMatz said:

Screenshot_6.png.a72be628e85365b0959df3c9487955e7.png

Sorry, Is this thing from the Windows Mixer, the green bar is the actual sound being played. So what i want to know if there is any way to check when that green bar goes up of 50% for example. 

You can just look for the pixels to change color, via Pixelsearch etc....  I’m not proud to say I’ve done it, but I have.

It does lag a bit though.   I’m sure there are better ways, though.

Code hard, but don’t hard code...

Link to comment
Share on other sites

lol, you got the easy way.  Just change one little thing and your script won't work anymore.  But if you are happy with your pixel approach, well I must say I am happy.  Because you have use the best programming language to do simple thing like you did !

FYI, I was able to get volume level of a session using MMDevice interface by using IAudioMeterInformation class, but it is not that clear how you could figure the 50% thing.  

Edited by Nine
Link to comment
Share on other sites

6 minutes ago, Nine said:

Because you have use the best programming language to do simple thing like you did !

True.  
IMHO, we are all here for a reason, and many of those reasons involve needing to do something on the fringes of mainstream programming.

In the case of the windows level monitoring, I have a teenage daughter upon whom I unleashed the full power of autoit when it caught her once again nudging her sound levels too high by slowly bring them back down into compliance:)

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

Thanks, actually i figured it to work for now, but now i found another problem.

While 1
Opt("PixelCoordMode", 1)
                $DetectarBoya = PixelSearch(52,220,54,223,0xE7EAEA,10,1)
                Do
                    $DetectarBoya = PixelSearch(52,220,54,223,0xE7EAEA,10,1)
                Until @error Or Sleep(600000)

WEnd

The problem is that i want to do it until pixel search don't found that pixel OR if +60secs have passed, it will end. How i manage this to work?

Link to comment
Share on other sites

Hey,

You need to find out the start time and calculate elapsed time every now often, and put that in an if

statement. I don't know the exact AutoIt functions, so please search for them, but the algortihm would look something like:

While 1
Opt("PixelCoordMode", 1)
                $DetectarBoya = PixelSearch(52,220,54,223,0xE7EAEA,10,1)
                Local $iStartTime = Get Current Time
                Do
                    $DetectarBoya = PixelSearch(52,220,54,223,0xE7EAEA,10,1)
                    Local $iCheckTime = Get Current Time                    
                Until @error Or $iCheckTime-$iStartTime >= 60000

WEnd

Just make sure the time format from the time function and condition (milliseconds in your case) is same

Edited by GokAy
Link to comment
Share on other sites

Don't misunderstood sound level. And sound level of the current sound played on the maximum sound level allowed by the "transistor" button. This is called saturation.

:huh2:

 

To be easier to understand :

If the maximum level is at 50% and you use 25% of this. Then the saturation is at 25%. It will help a lot if you do researches. 

  

On 2/28/2013 at 2:50 PM, JohnOne said:

Had a bit of time, so converted some code I found into a dll.

 

Original code is written by LARRY OSTERMAN http://blogs.msdn.com/b/larryosterman/

 

includes example

 

$V7Voldll = "V7Vol.dll"

$aDllCall = DllCall($V7Voldll, 'float', 'getvol')
If @error Then
    Exit MsgBox(0,"Error",@error)
EndIf

MsgBox(0,"Result",Round($aDllCall[0],2) * 100)

V7Vol.rar

 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

Would a WMI call find the actual value from the audio sub-system, rather than a picture search that could break depending on what sound mixer app the end user is using?

Fast, consistent, and accurate.

For example, on my system my volume control is horizontal, so your pixel search code would have to allow for that. How about multi-screen systems - where to start? How about different languages, and middle eastern Arabic right-to-left layouts? How about different sound devices and names?

Can I offer a hint: Pixel Search will NOT elegantly solve the problem you are seeking to solve. I'd be keen to see the source code of that $V7Vol dll you are calling, as it probably just asks Windows directly, something a WMI call will possibly also do.

Edited by Confuzzled
Link to comment
Share on other sites

48 minutes ago, Confuzzled said:

Can I offer a hint: Pixel Search will NOT elegantly solve the problem you are seeking to solve.

Depends how much time you have to do it and how well and long it needs to work.

For instance, maybe you’re just working on a demo or POC, and it’s just a minor part of a larger project that would be nice to have.

So you don’t have hours to spend.   

Code hard, but don’t hard code...

Link to comment
Share on other sites

On 11/3/2020 at 10:33 AM, caramen said:

Don't misunderstood sound level. And sound level of the current sound played on the maximum sound level allowed by the "transistor" button. This is called saturation.

:huh2:

 

To be easier to understand :

If the maximum level is at 50% and you use 25% of this. Then the saturation is at 25%. It will help a lot if you do researches. 

  

 

Ive checked that code and it just give the actual master volume, and i want what you called "saturation" but still searching for, im not able to found something.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...