Sometimes you may need to be able analyzing live audio stream using AWT2 watermark decoder. Here is an efficient recipe on establishing live analysis of audio stream from sound card (mic or line-in) using all freeware tools on Microsoft Windows machine.
- SoX (Sound eXchange) – http://sox.sourceforge.net (used for live recording of audio from sound card)
- Blat – http://blat.net (command line utility that sends eMail using SMTP)
Create a folder, extract SoX and Blat packages into it. Put AWT2 decoder into it. You should have approximately the following files structure:
blat.dll pthreadgc2.dll zlib1.dll awt2_dec.exe blat.exe sox.exe
Create a batch-file, call it ‘AWT2Monitor-runme.bat’ (without quotes). This batch continuously monitors (listens to) audio stream by invoking sound recording and watermark detection every N seconds. The contents of the batch:
@REM === Audio stream monitoring definitions @SET slicelen= 16 @SET slicestep= 8 @REM === Entering infinite loop @echo start > result.txt @SET /a waitsec= 1 + slicestep :Start @REM Get current timestamp in a form: @REM DD-MM-YYYY-HH-MM-SS-ms (e.g. 10-02-2013-21-04-46-48) @set SAVESTAMP=%DATE:/=-%-%TIME::=-% @set SAVESTAMP=%SAVESTAMP: =% @set SAVESTAMP=%SAVESTAMP:,=-% @set SAVESTAMP=%SAVESTAMP:.=-% @REM Start recording audio slice from the 'default' sound @REM device and analyze it using AWT2 decoder @start /SEPARATE /MIN call _rec_and_analyze.bat %SAVESTAMP%.wav %slicelen% @REM Wait 8 seconds before the next slice @PING 127.0.0.1 -n %waitsec% -w 1000 > nul @more result.txt @goto Start
The batch file runs continuously in the infinite loop. You will need to close its window to stop the listening process.
You can change time delay (step) between recorded audio slices by changing the value of ‘slicestep’ variable (in the example above the recording is performed every 8 seconds). You can change the length of the recorded audio stream slice y changing the value of ‘slicelen’ variable (in the example above the slice length is set to 16 seconds). With these recording settings, the recorded slices overlap, that provides reliable monitoring of the audio stream.
Create another batch file, call it ‘_rec_and_analyze.bat’ (without quotes). Here are the contents of this batch:
@REM Running SoX tool to record N sec long slice from the 'default' sound card @sox.exe --channels 1 --rate 44100 --bits 16 -d "%1" trim 0 %2 @REM Running AWT2 decoder to analyze the recorded slice @awt2_dec.exe "%1" 4 -silent >"%1".txt @IF NOT EXIST "%1" goto panic @REM storing result as text to show in the main listener loop @SET /p res= < "%1".txt @echo %1 - %res% > result.txt @REM Check whether a watemark was found more "%1".txt | find /i "No watermark" @IF ERRORLEVEL 1 goto watermark @IF NOT ERRORLEVEL 1 goto nowatermark :watermark @ECHO !Watermark detected! @mkdir Watermarked @copy "%1" Watermarked\ @copy "%1".txt Watermarked\ @REM Send e-mail with attached WAVE file and watermark in the subject blat -SaveSettings -f firstname.lastname@example.org -server mail.com -port 26 -u user -pw pswrd blat "%1".txt -attach "%1" -to email@example.com -i "AWT2_Analyzer" -subject "watermark found" @goto ext :nowatermark @ECHO !No watermark! @goto ext :ext @del "%1" @del "%1".txt @exit :panic @ECHO Could not record audio! Panic! @echo Could not record audio > result.txt @exit
This batch performs recording from the sound card input into a wave file (audio slice) and then performs watermark detection in the recorded wave using AWT2 decoder. If a watermark is detected, the recorded wave file is sent by e-mail in the attachment together with the information about detected watermark in the message body. You need to put appropriate information into mail addresses and mail server parameters in the Blat tool calling string. All watermarked waves are stored in ‘watermarked’ sub-folder. In case of no watermark, the recorded audio slice is deleted.
You should have the following files structure:
_rec_and_analyze.bat AWT2Monitor-runme.bat blat.dll pthreadgc2.dll zlib1.dll awt2_dec.exe blat.exe sox.exe
Before running this simple monitoring system, make the desired sound card input to be the default recording audio source in your Windows OS (in Windows 7, go to “Recording devices” tab, right-click with your mouse on the desired sound card input and chose “Set as Default Device”). In the audio device properties (or in the volume mixer) set appropriate recording level to avoid audio signal clipping.
Run ‘AWT2Monitor-runme.bat’ to start live audio stream listening and analysis.