Cybergon Posted October 28, 2015 Share Posted October 28, 2015 Hi forum it's been a while since I posted, been pretty busy. I've been tinkering with a little script to make my pc behave how I want it to. So far so good but there is one variable I'd like to tap into, and that is how loud my speakers are playing. I've been searching sparingly for weeks trying to find a way to do this to no avail. Only now did I think about asking you guys, I hope its not a problem.You can actually see what I'm talking about if you go to your playback devices, I attached a picture of it. So how is this value measured (without using pixelgetcolor or any screen tricks) to use in a script? Link to comment Share on other sites More sharing options...
Damein Posted October 30, 2015 Share Posted October 30, 2015 You can check this out: https://www.autoitscript.com/forum/topic/107462-volume-display/#comment-757850 Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
Cybergon Posted October 31, 2015 Author Share Posted October 31, 2015 You can check this out: https://www.autoitscript.com/forum/topic/107462-volume-display/#comment-757850That code is just colored bars going up, down & randomly. I'm looking for a way to measure the volume output level of my pc. Link to comment Share on other sites More sharing options...
Danyfirex Posted October 31, 2015 Share Posted October 31, 2015 expandcollapse popup#include <GuiConstants.au3> #include <ProgressConstants.au3> Global Const $S_OK = 0 ;=============================================================================== #interface "IMMDeviceEnumerator" Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}" Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}" ; Definition Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _ "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _ "GetDevice hresult(wstr;ptr*);" & _ "RegisterEndpointNotificationCallback hresult(ptr);" & _ "UnregisterEndpointNotificationCallback hresult(ptr);" ;=============================================================================== ;=============================================================================== #interface "IMMDevice" Global Const $sIID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}" ; Definition Global Const $tagIMMDevice = "Activate hresult(clsid;dword;variant*;ptr*);" & _ "OpenPropertyStore hresult(dword;ptr*);" & _ "GetId hresult(ptr*);" & _ "GetState hresult(dword*);" ;=============================================================================== ;=============================================================================== #interface "IAudioMeterInformation" Global Const $sIID_IAudioMeterInformation = "{C02216F6-8C67-4B5B-9D00-D008E73E0064}" ; Definition Global Const $tagIAudioMeterInformation = "GetPeakValue hresult(float*);" & _ "GetMeteringChannelCount hresult(dword*);" & _ "GetChannelsPeakValues hresult(dword;float*);" & _ "QueryHardwareSupport hresult(dword*);" ;=============================================================================== Global $oAudioMeterInformation = _AudioVolObject() If Not IsObj($oAudioMeterInformation) Then Exit -1 ; Will happen on non-supported systems Global $hGUI Global $hControl = _MakePeakMeterInWindow($hGUI) ; Register function to periodically update the progress control AdlibRegister("_LevelMeter", 45) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd AdlibUnRegister() ; Bye, bye... Func _MakePeakMeterInWindow($hWindow) $hWindow = GUICreate("ABC", 80, 300) Return GUICtrlCreateProgress(20, 20, 40, 260, $PBS_VERTICAL) EndFunc ;==>_MakePeakMeterInWindow Func _LevelMeter() Local $iPeak If $oAudioMeterInformation.GetPeakValue($iPeak) = $S_OK Then $iCurrentRead = 100 * $iPeak GUICtrlSetData($hControl, $iCurrentRead + 1) GUICtrlSetData($hControl, $iCurrentRead) EndIf EndFunc ;==>_LevelMeter Func _AudioVolObject() ; Sequences of code below are taken from the source of plugin written for AutoIt for setting master volume on Vista and above systems. ; Code was written by wraithdu in C++. ; MMDeviceEnumerator Local $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator) If @error Then Return SetError(1, 0, 0) Local Const $eRender = 0 Local Const $eConsole = 0 ; DefaultAudioEndpoint Local $pDefaultDevice $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDefaultDevice) If Not $pDefaultDevice Then Return SetError(2, 0, 0) ; Turn that pointer into object Local $oDefaultDevice = ObjCreateInterface($pDefaultDevice, $sIID_IMMDevice, $tagIMMDevice) Local Const $CLSCTX_INPROC_SERVER = 0x1 ; AudioMeterInformation Local $pAudioMeterInformation $oDefaultDevice.Activate($sIID_IAudioMeterInformation, $CLSCTX_INPROC_SERVER, 0, $pAudioMeterInformation) If Not $pAudioMeterInformation Then Return SetError(3, 0, 0) Return ObjCreateInterface($pAudioMeterInformation, $sIID_IAudioMeterInformation, $tagIAudioMeterInformation) EndFunc ;==>_AudioVolObjectSaludos Cybergon, trancexx and LarsJ 3 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Cybergon Posted November 6, 2015 Author Share Posted November 6, 2015 expandcollapse popup#include <GuiConstants.au3> #include <ProgressConstants.au3> Global Const $S_OK = 0 ;=============================================================================== #interface "IMMDeviceEnumerator" Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}" Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}" ; Definition Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _ "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _ "GetDevice hresult(wstr;ptr*);" & _ "RegisterEndpointNotificationCallback hresult(ptr);" & _ "UnregisterEndpointNotificationCallback hresult(ptr);" ;=============================================================================== ;=============================================================================== #interface "IMMDevice" Global Const $sIID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}" ; Definition Global Const $tagIMMDevice = "Activate hresult(clsid;dword;variant*;ptr*);" & _ "OpenPropertyStore hresult(dword;ptr*);" & _ "GetId hresult(ptr*);" & _ "GetState hresult(dword*);" ;=============================================================================== ;=============================================================================== #interface "IAudioMeterInformation" Global Const $sIID_IAudioMeterInformation = "{C02216F6-8C67-4B5B-9D00-D008E73E0064}" ; Definition Global Const $tagIAudioMeterInformation = "GetPeakValue hresult(float*);" & _ "GetMeteringChannelCount hresult(dword*);" & _ "GetChannelsPeakValues hresult(dword;float*);" & _ "QueryHardwareSupport hresult(dword*);" ;=============================================================================== Global $oAudioMeterInformation = _AudioVolObject() If Not IsObj($oAudioMeterInformation) Then Exit -1 ; Will happen on non-supported systems Global $hGUI Global $hControl = _MakePeakMeterInWindow($hGUI) ; Register function to periodically update the progress control AdlibRegister("_LevelMeter", 45) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd AdlibUnRegister() ; Bye, bye... Func _MakePeakMeterInWindow($hWindow) $hWindow = GUICreate("ABC", 80, 300) Return GUICtrlCreateProgress(20, 20, 40, 260, $PBS_VERTICAL) EndFunc ;==>_MakePeakMeterInWindow Func _LevelMeter() Local $iPeak If $oAudioMeterInformation.GetPeakValue($iPeak) = $S_OK Then $iCurrentRead = 100 * $iPeak GUICtrlSetData($hControl, $iCurrentRead + 1) GUICtrlSetData($hControl, $iCurrentRead) EndIf EndFunc ;==>_LevelMeter Func _AudioVolObject() ; Sequences of code below are taken from the source of plugin written for AutoIt for setting master volume on Vista and above systems. ; Code was written by wraithdu in C++. ; MMDeviceEnumerator Local $oMMDeviceEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator) If @error Then Return SetError(1, 0, 0) Local Const $eRender = 0 Local Const $eConsole = 0 ; DefaultAudioEndpoint Local $pDefaultDevice $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDefaultDevice) If Not $pDefaultDevice Then Return SetError(2, 0, 0) ; Turn that pointer into object Local $oDefaultDevice = ObjCreateInterface($pDefaultDevice, $sIID_IMMDevice, $tagIMMDevice) Local Const $CLSCTX_INPROC_SERVER = 0x1 ; AudioMeterInformation Local $pAudioMeterInformation $oDefaultDevice.Activate($sIID_IAudioMeterInformation, $CLSCTX_INPROC_SERVER, 0, $pAudioMeterInformation) If Not $pAudioMeterInformation Then Return SetError(3, 0, 0) Return ObjCreateInterface($pAudioMeterInformation, $sIID_IAudioMeterInformation, $tagIAudioMeterInformation) EndFunc ;==>_AudioVolObjectSaludosWow that's pretty neat! Modified _LevelMeter() to return $iCurrentRead instead of showing it and it's working like a charm!Gracias :-) Link to comment Share on other sites More sharing options...
Danyfirex Posted November 6, 2015 Share Posted November 6, 2015 You're Wellcome.Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Damein Posted November 11, 2015 Share Posted November 11, 2015 Weird but on my PC the link I posted shows the actual volume level as sound is output. Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now