tgeo has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, i am totaly new to this and i need a little help with a script i found over the net.
I have setup an Asterisk PBX that records calls and stores the files in a directory with the folowing names:
Outgoing calls: PBX-OUT-called_number-date-time-unique id.wav
eg: PBX-OUT-92610999999-20121212-145901-1355317141.98146.wav
The above outgoing call when tranfered to int 119: PBX-INTERNAL-called_number-int-date-time-unique id.wav
eg: PBX-INTERNAL-92610999999-119-20121212-145930-1355317141.98146.wav
Notice that both files have the same unique id
Incoming calls: PBX-IN-caller_id-date-time-unique id.wav
eg: PBX-IN-2610999999-20121212-150012-1355317212.9848.wav
The above incomming call when tranfered to int 119: PBX-INTERNAL-caller_id-int-date-time-unique id.wav
eg: PBX-INTERNAL-2610999999-119-20121212-150134-1355317212.9848.wav
Notice that both files have the same unique id
Internal calls: PBX-INTERNAL-from int-to int-date-time-unique id.wav
PBX-INTERNAL-206-120-20121212-160547-1355317520.9958.wav
I need the script to do the folowing:
1. Delete all internal files with filename PBX-INTERNAL-XXX-XXX.*
2. Mix incoming or outgoing call file with internal (tranfered) recording based on the unique id using sox.
eg: PBX-IN-2610999999-20121212-150012-1355317212.9848.wav + PBX-INTERNAL-2610999999-119-20121212-150134-1355317212.9848.wav should make a new file with name PBX-IN-2610999999-20121212-150012-1355317212.9848.wav
3. convert .wav to .mp3 (it is works already)
4. delete converted .wav files (it is works already)
5. move .mp3 files to another server (it is works already)
here is the script
#!/usr/bin/perl $path='/var/spool/asterisk/monitor'; $mount='/mnt/nas/'; @Files = glob($path.'/*.wav'); foreach $File (@Files) { if((-M $File)>0.0002) { if(($FileName)=($File=~/(.+)\-out.wav/)) { system("/usr/bin/sox -m $FileName-in.wav $File +Name-out.wav $FileName.wav"); unlink "$FileName-in.wav"; unlink "$FileName-out.wav"; } elsif(($FileName)=($File=~/(.+)\-in.wav/)) { system("/usr/bin/sox -m $FileName-in.wav $File +Name-out.wav $FileName.wav"); unlink "$FileName-in.wav"; unlink "$FileName-out.wav"; } else { ($FileName) = ($File=~/(.+)\.wav/); } print "Creating $FileName.mp3\n"; system("/usr/bin/lame --cbr -b 32 --noreplaygain -q 2 \"$FileName.wav\ +" \"$FileName.mp3\" --quiet"); if(-e "$FileName.mp3") { print "Moving $FileName.mp3 to $mount\n"; system("mv ".$FileName.".mp3 ".$mount); print "Deleting $FileName.wav\n"; unlink "$FileName.wav"; } } }
Can someone please help
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Need help modifing a script
by roboticus (Chancellor) on Dec 19, 2012 at 13:01 UTC | |
Re: Need help modifing a script
by bart (Canon) on Dec 19, 2012 at 12:51 UTC |