请问一下 怎么监视声音 谢谢
我想知道 怎么监视右下角的声音 里面的比如 波形它被关小了 怎么知道它变小了 这个有点难,坐个沙发来等高手! WIN7中控制的是本程序的音量vwaveoutgetvolume取不到音量大小。开始播放了,waveoutsetvolume可以成功控制本程序音量大小;Get Wav Sound Volume; Author gafrost
#include <GUIConstants.au3>
MsgBox(0,"", _SoundGetWaveVolume())
Func _SoundGetWaveVolume()
Local $WaveVol = -1, $p, $ret
Const $MMSYSERR_NOERROR = 0
$p = DllStructCreate ("dword")
If @error Then
SetError(2)
Return -2
EndIf
$ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr ($p))
If ($ret == $MMSYSERR_NOERROR) Then
$WaveVol = Round(Dec(StringRight(Hex(DllStructGetData ($p, 1), 8), 4)) / 0xFFFF * 100)
Else
SetError(1)
EndIf
$Struct=0
Return $WaveVol
EndFunc;==>_SoundGetWaveVolume
本帖最后由 lainline 于 2013-1-25 20:54 编辑
这个例子更明显
打开合成器
小键盘+加音量
-减音量HotKeySet("{NUMPADADD}", "Volume_Add")
HotKeySet("{NUMPADSUB}", "Volume_Sub")
func Volume_Prog_Bar()
$Volume_Bar = ""
for $i = 1 to 10 step 1
if Volume_Get() / 10 >= $i Then
$Volume_Bar &= "|"
Else
$Volume_Bar &= "-"
endif
next
$Volume_Display = Volume_Get() & "% " & $Volume_Bar
Return $Volume_Display
EndFunc
func Volume_Add()
if Volume_Get() < 100 then
SoundSetWaveVolume(Volume_Get() + 10)
ToolTip(Volume_Prog_Bar())
Sleep(1000)
ToolTip('')
EndIf
EndFunc
func Volume_Sub()
if Volume_Get() > 0 then
SoundSetWaveVolume(Volume_Get() - 10)
ToolTip(Volume_Prog_Bar())
Sleep(1000)
ToolTip('')
EndIf
EndFunc
Func Volume_Get()
Local $WaveVol = -1, $p, $ret
Const $MMSYSERR_NOERROR = 0
$p = DllStructCreate ("dword")
If @error Then
SetError(2)
Return -2
EndIf
$ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr ($p))
If ($ret == $MMSYSERR_NOERROR) Then
$WaveVol = Round(Dec(StringRight(Hex(DllStructGetData ($p, 1), 8), 4)) / 0xFFFF * 100)
Else
SetError(1)
EndIf
$Struct=0
Return $WaveVol
EndFunc
While 1
Sleep(100)
WEnd
我也想知道结果。{:face (332):} http://www.autoitscript.com/forum/topic/84834-control-vista-master-volume/page__hl__%20mixer 简化了下代码做了个示例 esc退出Global Const $CLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $IID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $tagIMMDeviceEnumerator = _
"EnumAudioEndpoints hresult(int;dword;ptr*);" & _
"GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
"GetDevice hresult(wstr;ptr*);" & _
"RegisterEndpointNotificationCallback hresult(ptr);" & _
"UnregisterEndpointNotificationCallback hresult(ptr)"
Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $tagIMMDevice = _
"Activate hresult(struct*;dword;ptr;ptr*);" & _
"OpenPropertyStore hresult(dword;ptr*);" & _
"GetId hresult(wstr*);" & _
"GetState hresult(dword*)"
Global Const $eRender = 0, $eConsole = 0
Global Const $IID_IAudioEndpointVolume = "{5CDF2C82-841E-4546-9722-0CF74078229A}"
Global Const $tagIAudioEndpointVolume = _
"RegisterControlChangeNotify hresult(ptr);" & _
"UnregisterControlChangeNotify hresult(ptr);" & _
"GetChannelCount hresult(uint*);" & _
"SetMasterVolumeLevel hresult(float;ptr);" & _
"SetMasterVolumeLevelScalar hresult(float;ptr);" & _
"GetMasterVolumeLevel hresult(float*);" & _
"GetMasterVolumeLevelScalar hresult(float*);" & _
"SetChannelVolumeLevel hresult(uint;float;ptr);" & _
"SetChannelVolumeLevelScalar hresult(uint;float;ptr);" & _
"GetChannelVolumeLevel hresult(uint;float*);" & _
"GetChannelVolumeLevelScalar hresult(uint;float*);" & _
"SetMute hresult(int;ptr);" & _
"GetMute hresult(int*);" & _
"GetVolumeStepInfo hresult(uint*;uint*);" & _
"VolumeStepUp hresult(ptr);" & _
"VolumeStepDown hresult(ptr);" & _
"QueryHardwareSupport hresult(dword*);" & _
"GetVolumeRange hresult(float*;float*;float*)"
Global Const $CLSCTX_INPROC_SERVER = 1
Global $__g_oEndpointVolume = 0
HotKeySet("{esc}","Exitfunc")
do
$s=_GetMasterVolumeLevelScalar()
ToolTip ($s)
Until 0
Func Exitfunc()
Exit 0
EndFunc
; #FUNCTION# ====================================================================================================================
; Name ..........: _GetMasterVolumeLevelScalar
; Description ...: Get master volume level in scalar units, 0.0 to 100.0.
; Syntax ........: _GetMasterVolumeLevelScalar()
; Parameters ....:
; Return values .: Success - Master volume level in scalar units, 0.0 to 100.0 (float)
; Failure - 0 and sets @error
; Author ........: Erik Pilsits
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GetMasterVolumeLevelScalar()
_EndpointVolume_Init()
If @error Then Return SetError(-1, 0, 0)
;
Local $iVol
If __SUCCEEDED($__g_oEndpointVolume.GetMasterVolumeLevelScalar($iVol)) Then
Return ($iVol * 100)
Else
Return SetError(1, 0, 0)
EndIf
EndFunc
Func _EndpointVolume_Init()
If IsObj($__g_oEndpointVolume) Then Return
$__g_oEndpointVolume = __GetDefaultEndpointVolume()
If @error Then Return SetError(@error)
EndFunc
Func __SUCCEEDED($hr)
Return ($hr >= 0)
EndFunc
Func __GetDefaultEndpointVolume()
Local $oIAudioEndpointVolume = 0, $err = 1
; create device enumerator interface
Local $oDevEnum = ObjCreateInterface($CLSID_MMDeviceEnumerator, $IID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)
If IsObj($oDevEnum) Then
$err = 2
; get default audio endpoint interface pointer
Local $pDefaultDevice = 0
If __SUCCEEDED($oDevEnum.GetDefaultAudioEndpoint($eRender, $eConsole, $pDefaultDevice)) Then
$err = 3
; create default audio endpoint interface
Local $oIMMDevice = ObjCreateInterface($pDefaultDevice, $IID_IMMDevice, $tagIMMDevice)
If IsObj($oIMMDevice) Then
$err = 4
; get endpoint volume interface pointer
Local $pEndpointVolume = 0
If __SUCCEEDED($oIMMDevice.Activate(__uuidof($IID_IAudioEndpointVolume), $CLSCTX_INPROC_SERVER, 0, $pEndpointVolume)) Then
$err = 5
; create endpoint volume interface
$oIAudioEndpointVolume = ObjCreateInterface($pEndpointVolume, $IID_IAudioEndpointVolume, $tagIAudioEndpointVolume)
EndIf
$oIMMDevice = 0
EndIf
EndIf
$oDevEnum = 0
EndIf
;
If IsObj($oIAudioEndpointVolume) Then
Return $oIAudioEndpointVolume
Else
Return SetError($err, 0, 0)
EndIf
EndFunc
Func __uuidof($sGUID)
Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4")
DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID)
If @error Then Return SetError(@error, @extended, 0)
Return $tGUID
EndFunc http://www.autoitscript.com/forum/topic/54048-audioau3/ 7楼的很给力,谢谢 正需要用来做外挂
页:
[1]