Что нового

Отслеживание громкости микрофона+запись звука

Arei

Скриптер
Сообщения
938
Репутация
115
есть 2 скрипта
1 скрипт отслеживает громкость звука в микрофоне
Код:
#Include <string.au3>
#include <GUIConstants.au3>
#include <misc.au3>
#include <GUIConstantsEx.au3>
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 1)

$dot = False
$bg = 0x222222
$graph = 0xFFFFFF
$run = True
Dim $lpszDevice
Dim $lpszDeviceID
Dim $lpszOpenFlags
Dim $lpszRequest
Dim $lpszFlags
Dim $lpszCommand
Dim $lpszReturnString
Dim $cchReturn
Dim $mciError
$lpszDevice = "new type waveaudio"
$lpszOpenFlags = "alias mywave"
$lpszFlags = ""
$lpszCommand = StringFormat("open %s %s %s", $lpszDevice, $lpszOpenFlags, $lpszFlags)
$lpszReturnString = _StringRepeat(" ", 100)
$cchReturn = StringLen($lpszReturnString)
$mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
If $mciError[0] <> 0 Then _mciShowError($mciError[0])
$lpszDeviceID = "mywave"
$lpszRequest = "level"
$lpszFlags = ""
$lpszCommand = StringFormat("status %s %s %s", $lpszDeviceID, $lpszRequest, $lpszFlags);
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 105, 183, 193, 115, -1)
$Progress1 = GUICtrlCreateProgress(9, 8, 39, 169)
GUICtrlSetColor(-1,0x0)
GUICtrlSetbkColor(-1,0x00FF00)
$Progress2 = GUICtrlCreateProgress(57, 8, 39, 169)

GUICtrlSetBkColor(-1,0x0)
GUICtrlSetColor(-1,0x00FF00)


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$run = True
While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
 If $run = True Then
        $mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
        If $mciError[0] <> 0 Then _mciShowError($mciError[0])
        $mciError = (100*$mciError[2])/100
        If $mciError > 100 Then $mciError = 150

        GUICtrlSetData($Progress1,$mciError)
        GUICtrlSetData($Progress2,$mciError)


 EndIf

WEnd

сама переменная получается в $mciError
2 код запись звука самого.
Код:
$filename="my1.wav"

func _startwav()
mciSendString("close all")
mciSendString("open new type waveaudio alias capture")
mciSendString("set capture bitspersample 16") ; 8, etc.
mciSendString("set capture samplespersec 22050") ; 44100, etc...
mciSendString("set capture channels 1") ; or 2
mciSendString("record capture")
EndFunc
; keep recording for 5 seconds

func _stopwav()
; stop and save recording to $filename
mciSendString("stop capture")
mciSendString('save capture "' & $filename & '" wait')
mciSendString("close capture")


EndFunc


;===============================================================================
; Description:     Send Windows Media Control Interface (MCI) string
; Parameter(s):    MCI command string. See command reference at:
;                  http://msdn.microsoft.com/en-us/library/ms710815(VS.85).aspx
; Requirement(s):  None
; Return Value(s): on success = 1, on fail = 0 and @error set to 1
;===============================================================================
Func mciSendString($s)
    DllCall("winmm.dll", "int", "mciSendString", "str", $s, "str", "", "int", 65534, "hwnd", 0)
    If @error Then
        SetError(1)
        Return 0
    Else
        Return 1
    EndIf
EndFunc

как объединить эти скрипты что бы записывалось когда громче n значения, и останавливалось когда после m значения.Мои знания не позволили сделать обращаюсь к форуму.Заранее спасибо.
 

dwerf

Использует ArchLinux
Сообщения
478
Репутация
219
В первом скрипте не хватает функций
  • _mciSendString
  • _mciShowError
 
Автор
A

Arei

Скриптер
Сообщения
938
Репутация
115
Спасибо не заметил.Вот полный код

Код:
#Include <string.au3>
#Include <GUIConstants.au3>
#include <misc.au3>
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 1)

$dot = False
$bg = 0x222222
$graph = 0xFFFFFF
$run = True
Dim $lpszDevice
Dim $lpszDeviceID
Dim $lpszOpenFlags
Dim $lpszRequest
Dim $lpszFlags
Dim $lpszCommand
Dim $lpszReturnString
Dim $cchReturn
Dim $mciError
$lpszDevice = "new type waveaudio"
$lpszOpenFlags = "alias mywave"
$lpszFlags = ""
$lpszCommand = StringFormat("open %s %s %s", $lpszDevice, $lpszOpenFlags, $lpszFlags)
$lpszReturnString = _StringRepeat(" ", 100)
$cchReturn = StringLen($lpszReturnString)
$mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
If $mciError[0] <> 0 Then _mciShowError($mciError[0])
$lpszDeviceID = "mywave"
$lpszRequest = "level"
$lpszFlags = ""
$lpszCommand = StringFormat("status %s %s %s", $lpszDeviceID, $lpszRequest, $lpszFlags);
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 105, 183, 193, 115, -1)
$Progress1 = GUICtrlCreateProgress(9, 8, 39, 169)
GUICtrlSetColor(-1,0x0)
GUICtrlSetbkColor(-1,0x00FF00)
$Progress2 = GUICtrlCreateProgress(57, 8, 39, 169)

GUICtrlSetBkColor(-1,0x0)
GUICtrlSetColor(-1,0x00FF00)


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$run = True
While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
;~  If $run = True Then
        $mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
        If $mciError[0] <> 0 Then _mciShowError($mciError[0])
        $mciError = (100*$mciError[2])/128
        If $mciError > 100 Then $mciError = 100
        GUICtrlSetData($Progress1,$mciError)
        GUICtrlSetData($Progress2,$mciError)
;~      Sleep(50)
;~  EndIf
    Sleep(10)
WEnd






Func SpecialEvents()
    Exit
EndFunc ;==>SpecialEvents

Func _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, $hwndCallback)
    Return DllCall("winmm.dll", "long", "mciSendStringA", "str", $lpszCommand, "str", $lpszReturnString, "long", $cchReturn, "long", 0)
EndFunc ;==>_mciSendString
Func _mciShowError($mciError)
    Dim $errStr; Error message
    $errStr = _StringRepeat(" ", 100); Reserve some space for the error message
    $Result = DllCall("winmm.dll", "long", "mciGetErrorStringA", "long", $mciError, "string", $errStr, "long", StringLen($errStr))
    MsgBox(0, "MCI test", "MCI Error Number " & $mciError & ":" & $Result[2])
EndFunc ;==>_mciShowError
 
Автор
A

Arei

Скриптер
Сообщения
938
Репутация
115
Код:
#Include <string.au3>
#Include <GUIConstants.au3>
#include <misc.au3>
DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 1)
$filename="my1.wav"
$dot = False
$bg = 0x222222
$graph = 0xFFFFFF
$run = True
Dim $lpszDevice
Dim $lpszDeviceID
Dim $lpszOpenFlags
Dim $lpszRequest
Dim $lpszFlags
Dim $lpszCommand
Dim $lpszReturnString
Dim $cchReturn
Dim $mciError

$lpszDevice = "new type waveaudio"
$lpszOpenFlags = "alias mywave"
$lpszFlags = ""
$lpszCommand = StringFormat("open %s %s %s", $lpszDevice, $lpszOpenFlags, $lpszFlags)
$lpszReturnString = _StringRepeat(" ", 100)
$cchReturn = StringLen($lpszReturnString)
$mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
If $mciError[0] <> 0 Then _mciShowError($mciError[0])
$lpszDeviceID = "mywave"
$lpszRequest = "level"
$lpszFlags = ""
$lpszCommand = StringFormat("status %s %s %s", $lpszDeviceID, $lpszRequest, $lpszFlags);
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 105, 183, 193, 115, -1)
$Progress1 = GUICtrlCreateProgress(9, 8, 39, 169)
GUICtrlSetColor(-1,0x0)
GUICtrlSetbkColor(-1,0x00FF00)
$Progress2 = GUICtrlCreateProgress(57, 8, 39, 169)

GUICtrlSetBkColor(-1,0x0)
GUICtrlSetColor(-1,0x00FF00)


GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$run = True
While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
;~  If $run = True Then
        $mciError = _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, 0);
        If $mciError[0] <> 0 Then _mciShowError($mciError[0])
        $mciError = (100*$mciError[2])/128
        If $mciError > 100 Then $mciError = 100
        GUICtrlSetData($Progress1,$mciError)
        GUICtrlSetData($Progress2,$mciError)

		if $mciError > 8  then
			_startwav()
			
		
		sleep(5000)
			_stopwav()
			
			EndIf



;~      Sleep(50)
;~  EndIf

WEnd






func _startwav()
mciSendString("open new type waveaudio alias capture")
mciSendString("set capture bitspersample 16") ; 8, etc.
mciSendString("set capture samplespersec 22050") ; 44100, etc...
mciSendString("set capture channels 1") ; or 2
mciSendString("record capture")
EndFunc
; keep recording for 5 seconds

func _stopwav()
; stop and save recording to $filename
mciSendString("stop capture")
mciSendString('save capture "' & $filename & '" wait')
mciSendString("close capture")


EndFunc


;===============================================================================
; Description:     Send Windows Media Control Interface (MCI) string
; Parameter(s):    MCI command string. See command reference at:
;                  http://msdn.microsoft.com/en-us/library/ms710815(VS.85).aspx
; Requirement(s):  None
; Return Value(s): on success = 1, on fail = 0 and @error set to 1
;===============================================================================
Func mciSendString($s)
    DllCall("winmm.dll", "int", "mciSendString", "str", $s, "str", "", "int", 65534, "hwnd", 0)
    If @error Then
        SetError(1)
        Return 0
    Else
        Return 1
    EndIf
EndFunc







Func SpecialEvents()
    Exit
EndFunc ;==>SpecialEvents

Func _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, $hwndCallback)
    Return DllCall("winmm.dll", "long", "mciSendStringA", "str", $lpszCommand, "str", $lpszReturnString, "long", $cchReturn, "long", 0)
EndFunc ;==>_mciSendString
Func _mciShowError($mciError)
    Dim $errStr; Error message
    $errStr = _StringRepeat(" ", 100); Reserve some space for the error message
    $Result = DllCall("winmm.dll", "long", "mciGetErrorStringA", "long", $mciError, "string", $errStr, "long", StringLen($errStr))

EndFunc ;==>_mciShowError

Сделал так,Спасибо за помощь. :IL_AutoIt_1:
 
Верх