AutoItで指定した音量以上になった時に反応させる
便利なものを作っている方がいます
MusicStarter
Enter your room and the music starts 😀 – AutoIt Example Scripts – AutoIt Forums (autoitscript.com)
スクリプトをコピーしてファイルに保存します。そのままで動かないので変更します。
AdlibEnable/AdlibDisable were replaced with AdlibRegister/AdlibUnRegister
guiバージョン
マウスクリックするにはイベントに
MouseClick("left")
指定した音量以上になったらクリックするサンプル
声を出したらクリックするサンプルです。最初にあるサンプルを少し変更しました。シンプルなものなので上にあるgui版を使った方が良いと思います
参考程度にしてください
;~ MusicStarter TestVersion(Modified SoundClick Version by eightban)
;~ By Nemcija (BlackShadow3@web.de)
;~ With UDF's by CyberZeroCool
;~SoundClick
;~ Just call it crap :D
;~ -----------------------------------------------------------------
#region Settings
$VoiceActivationLevel = 25 ; Use Debugmode to determine this
$SleepBeforeCheck = 10 ;Seconds bevor start checking the microphonelevel (time to leave the room :D)
$Debugmode = false ;To determine the activation level
#endregion Settings
#region Includes
#Include <string.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#endregion Includes
#region Functions
Func _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, $hwndCallback)
Return DllCall("winmm.dll", "long", "mciSendStringA", "str", $lpszCommand, "str", $lpszReturnString, "long", $cchReturn, "long", 0)
EndFunc
Func _mciShowError($mciError,$add = "test")
Dim $errStr
$errStr = _StringRepeat(" ", 256)
$Result = DllCall("winmm.dll", "long", "mciGetErrorStringA", "long", $mciError, "string", $errStr, "long", StringLen($errStr))
MsgBox(0, "MCI "&$add, "MCI Error Number " & $mciError & ":" & $Result[2])
EndFunc ;==>_mciShowError
Func _LevelCheck()
Global $lpszCommand,$lpszReturnString,$cchReturn
$mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0)
If $mciError[0] <> 0 Then
_mciShowError($mciError[0])
EndIf
_AddToLastLevels($mciError[2])
EndFunc
Func _AddToLastLevels($level)
Global $LastLevels,$LevelTime,$Debugmode
$LastLevels[$LastLevelsSet] = $level
$LastLevelsSet += 1
If $Debugmode Then ToolTip($level)
If $LastLevelsSet = $LevelTime+1 Then $LastLevelsSet = 1
EndFunc
#endregion Functions
#region Startup
$lpszDevice = "new type waveaudio"
$lpszOpenFlags = "alias mywave"
$lpszFlags = ""
$lpszCommand = StringFormat( "open %s %s %s", $lpszDevice, $lpszOpenFlags, $lpszFlags)
$lpszReturnString = _StringRepeat(" ", 256)
$cchReturn = StringLen($lpszReturnString)
$mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
If $mciError[0] <> 0 Then
_mciShowError($mciError[0],"Startup Error")
Exit
EndIf
$lpszDeviceID = "mywave"
$lpszRequest = "level"
$lpszFlags = ""
$lpszCommand = StringFormat( "status %s %s %s", $lpszDeviceID, $lpszRequest, $lpszFlags)
$LevelTime = 15 ; *100ms
Dim $LastLevels[$LevelTime+1]
For $i = 1 To $LevelTime
$LastLevels[$i] = 0
Next
$LastLevelsSet = 1
AdlibRegister("_LevelCheck",100)
#endregion Startup
Global $_title_1 = "SoundClick"
;[CLASS:Windows.UI.Core.CoreWindow; INSTANCE:0]
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$mainwindow = GUICreate($_title_1, 70, 70)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$msg1="stopping"
$label1=GUICtrlCreateLabel($msg1, 10, 10)
$button1 = GUICtrlCreateButton("push", 10, 20,50, 50)
GUICtrlSetOnEvent($button1, "OKButton")
GUISetState(@SW_SHOW)
HotKeySet("{Esc}", "_Exit") ; Press ESC for exit
Func _Exit()
Exit 0
EndFunc ;==>_Exit
Func OKButton()
; MsgBox(0, "GUI Event", "You pressed OK!")
if $msg1="stopping" Then
$msg1="executing"
;Sleep($SleepBeforeCheck*1000)
Msgbox(4096,"wait", "start after "&$SleepBeforeCheck,$SleepBeforeCheck)
Else
$msg1="stopping"
EndIf
GUICtrlSetData ($label1, $msg1)
EndFunc
Func CLOSEClicked()
; MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
Exit
EndFunc
#region Runtime
;Sleep($SleepBeforeCheck*1000)
While 1
if $msg1="stopping" Then
Else
Sleep(100)
$Active = False
$i = 0
While (($i <= $LevelTime) And ($Active==False))
$levx=Int($LastLevels[$i])
If ($levx >=$VoiceActivationLevel) Then
$Active=True
$activestate=1; +1 max
ExitLoop
EndIf
$i +=1
WEnd
;ConsoleWrite(" "&$levx)
If $Active Then
ConsoleWrite(@CRLF&"active "&$levx)
MouseClick("left")
; Send("{MEDIA_PLAY_PAUSE}")
Sleep(2000)
; Exit
EndIf
EndIf
WEnd
#endregion Runtime
ディスカッション
コメント一覧
まだ、コメントがありません