darzanmihai Posted November 27, 2009 Share Posted November 27, 2009 Hello. I need some help with my script. I want to make a script that records sound from the microphone when the sound passes a certain level. I managed to do this, but there are 3 problems: - sometimes the sound level resulted from my function isn't always corect (most of the times is 128 when is silence and sometimes stais 3-8 even if I speek in the mic). - from 5 recordings made, 2 are just loud fuzzy noise. - the recording begins even if the sound level is not in the limit 20-80 as I setted it to be. Here is the code I wrote: expandcollapse popup#include <Media.au3> #include <string.au3> Global $rec = 1 Global $VoiceActivationLevel = 20 Global $RecTime = 60000;ms $lpszReturnString = _StringRepeat(" ", 256) $cchReturn = StringLen($lpszReturnString) $mciError = _mciSendString("open new type waveaudio alias tempwave", $lpszReturnString, $cchReturn, 0); If $mciError[0] <> 0 Then _mciShowError($mciError[0], "Startup Error") Exit EndIf $timer = TimerInit() $count_hit = 0 While 1 $level = 0 If $rec = 1 Then SoundLevelChk() ToolTip("Voice a level =" & $VoiceActivationLevel & @CRLF & "level =" & $level, 10, 10, "SOUND_REC") If $level >= $VoiceActivationLevel And $level <= 80 Then $count_hit += 1 If $count_hit >= 2 Then ToolTip("Voice a level =" & $VoiceActivationLevel & @CRLF & "level =" & $level, 10, 10, "SOUND_REC - HIT") Record() $count_hit = 0 EndIf Else $count_hit = 0 EndIf EndIf Sleep(50) WEnd 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, $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 SoundLevelChk() Global $lpszCommand, $lpszReturnString, $cchReturn $level = 0 $mciError = _mciSendString("status tempwave level", $lpszReturnString, $cchReturn, 0) If $mciError[2] > 0 Then If $mciError[0] = 0 Then $level = $mciError[2] EndIf EndFunc ;==>SoundLevelChk Func Record() $File = @ScriptDir & "\trimise\" & @MDAY & @MON & @YEAR & @HOUR & @MIN & @SEC & ".wav" If Not FileExists(@ScriptDir & "\trimise") Then DirCreate(@ScriptDir & "\trimise") $Media = _MediaCreate(6) If Not @error Then _MediaRecord($Media) If Not @error Then $counter_rec = TimerInit() While 1 If TimerDiff($counter_rec) >= $RecTime Then $counter_rec = "" ExitLoop EndIf Sleep(100) WEnd _MediaStop($Media) If Not @error Then _MediaSave($Media, $File) EndIf _MediaClose($Media) Else _MediaStop($Media) If @error Then _MediaClose($Media) EndIf EndIf Else _MediaClose($Media) EndIf EndFunc ;==>Record and this is the Media.au3 file i Used: I do not like stupid and idiot people that write idiot things...If you are one, do not write. Link to comment Share on other sites More sharing options...
BrettF Posted November 28, 2009 Share Posted November 28, 2009 BASS.dll (check sig. From memory you are looking for the examples included with BASSENC...) does have recording functionality... Maybe worthy to check out. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
darzanmihai Posted November 30, 2009 Author Share Posted November 30, 2009 BASS.dll (check sig. From memory you are looking for the examples included with BASSENC...) does have recording functionality... Maybe worthy to check out.Thx for reply.I tried the bass.dll, and it works super ok, but the size of the file is to large. could you give me an example with bass.dll for the smallest possible size made with it? I do not like stupid and idiot people that write idiot things...If you are one, do not write. Link to comment Share on other sites More sharing options...
darzanmihai Posted December 7, 2009 Author Share Posted December 7, 2009 Thx for reply.I tried the bass.dll, and it works super ok, but the size of the file is to large. could you give me an example with bass.dll for the smallest possible size made with it?someone? I do not like stupid and idiot people that write idiot things...If you are one, do not write. Link to comment Share on other sites More sharing options...
darzanmihai Posted December 10, 2009 Author Share Posted December 10, 2009 I tryed to do something with the bass.dll, but the file size is to large...could someone help me on this matter with an example? Thx in advance I do not like stupid and idiot people that write idiot things...If you are one, do not write. Link to comment Share on other sites More sharing options...
BrettF Posted December 11, 2009 Share Posted December 11, 2009 What do you mean too large? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
darzanmihai Posted December 16, 2009 Author Share Posted December 16, 2009 What do you mean too large?With bass.dll I managed to create sound files with aprox. 87kbps, but with the script I posted the sound file resulted has aprox 10 kbps.I'd like to create sound files with bass.dll with aprox 10kbps or smaller if possible because for a recording time of 30 minutes, the recording file size will be 152 MB with 87kbps and 17 MB with 10kbps.If you could help me with this it will be greatly apreciated.Thx in advance. I do not like stupid and idiot people that write idiot things...If you are one, do not write. 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