Converting recorded wav calls to mp3

you can add a command to the for loop between the ultlmate comma and done something like

mysql -ppassword -uuser asteriskcdrdb -e "update cdr set recordingfile='${i%.wav}.mp3' where recordingfile='$i'";

That might work, I havn’t tried it

This is probably more a question for dicko

Using information in one of your earlier posts, rather than running a cron job I am running my conversion scrip(s) to be called on by the utilizing the “Post Call Recording Script”, which I like a LOT more.

My question, since I am no where near proficient in Perl, is how do I remove my loop without stopping the rest of the script from running?

Here is a section I cut out that contains the loop, any ideas you could give me would be greatly appreciated!

if ( $Today eq $QDate )
{ print "sleeping ";sleep 10}
print " loop “;
my $NumRec = 0;
while( my $info = $sth->fetchrow_hashref){
$NumRec++;
my %i2 = %{$info}; #Easier to read
my @subdir = split( ‘-’, substr($i2{‘calldate’},0,10));
my $file = $config{‘monitor_base’} . ‘/’ . join (’/’ , @subdir) . “/$i2{‘recordingfile’}”;
$config{‘archiveDir’} = “/var/spool/asterisk/wavarchive/” . join (’/’ , @subdir) . ‘/’;
my ($archivo, $directorio, $suffix) = fileparse($file , ‘.wav’ );
printf “\n%5.0d %-60s " , $NumRec,”$archivo$suffix” ;#archive=$archivo directory=$directorio suffix=$suffix “;
next unless $suffix eq ‘.wav’;
#print " archive=$archivo directory=$directorio suffix=$suffix “;
if ( -f $file ){
mp3me($dbh,$file,$i2{‘recordingfile’},$i2{‘calldate’},$i2{‘cnam’},$i2{‘lastapp’});
print " Updated to MP3”;
} else {
print “Not Found! Duration $i2{‘duration’}”;
my $NewFile = $file;
$NewFile =~ s/.wav$/.mp3/;
if ( -f $NewFile ){
print “\n$file\n$NewFile\n OH an mp3 exists need to update the database record\n”;
my $Mquery = "
UPDATE cdr
SET recordingfile = REPLACE(recordingfile, ‘.wav’, ‘.mp3’)
WHERE calldate = ‘$i2{‘calldate’}’ AND recordingfile = ‘$i2{‘recordingfile’}’
LIMIT 3”;
print “\n$Mquery”;
my $numrows = $dbh->do($Mquery);
if ( not defined $numrows) {
print STDERR “ERROR: $DBI::errstr”;
} else {
print STDERR “\tINFO: $numrows rows updated”;
}
}
}

I’m not sure I ever posted a perl script, perhaps I did but bash is easily capable of doing anything you want, post both the script and the way you call it with all it’s parameter

Thanks for responding Dicko!
Originally I was trying to figure out why my script wouldn’t process more than one recording at a time when executed by a cron, but would process all available if I ran it manually. Using the GUI feature “Post Call Recording Script”, makes it run automatically after each call, which I think will be better, AND I won’t have to worry about solving the issue I have running it with a cron job.

I posted both the bash and perl scripts above on Jan 9th. It is really long so I don’t want to take up too much real estate by posting it again, but the script that starts the process is bash:

#!/bin/bash

TODAY=date +%F
echo “
–START-------------
”date >> /tmp/MP3convert.log
/usr/local/bin/wav2mp3/ls_rec_file.pl $TODAY | tee -a /tmp/MP3convert$TODAY.log | mail -r [email protected] -s “CES MP3 Convert” [email protected]

I did throw that in the Post Call box in the GUI and it ran great. Unfortunately I didn’t process them manually first, so there were about 250 wav’s to convert, and within a few seconds it had multiple instance trying to process all of the files at once… makes for an interesting HTOP to watch. Please note that I inherited the scripts and am just trying to make it work unattended for now, and later on I will try to come up with something much simpler to test on my test pbx.

Thanks for looking at this for me!

Hey dicko,
Forgive me as I’m not well versed in handling audio files on linux. Are the methods used in the scripts in this thread using the lame package to convert to MP3 and you are saying you use the sox package (complied with liblame) to perform the conversion? And this conversion is quicker? And you would change the scripts from running;

nice lame -b 32 -m m "$dtpath$1.wav" "$dtpath$1.mp3"

to a command using sox instead?

Thanks.

Using sox with soxlib-fmt-mp3 installed instead of lame, just replace the call to lame with one to sox.

sox “$dtpath$1.wav” “$dtpath$1.mp3”

Thanks. I found there is a settings in FreePBX to change the recordings from wav to WAV (WAV49) and am considering just doing that instead. Seems simpler and probably negligible difference in storage savings to mp3 (for me at least).

I’m seeing two issues currently.

  • The “call recording report” in FreePBX is showing the “duration” incorrectly now that it’s set to WAV49 (a 3min call showed 6sec). The playback works fine though.
  • CPU spikes to 99% for a 1-2sec. I’d assume it was the conversion causing it but what I see is a mysql PID. I haven’t seen this behavior before and I’m thinking perhaps it is related to the recording in some way.

Well, choose a good value for nice and it should play well with the other kids, mp3 wav WAV etc. have in the past been problematic as android iphones windoze ios etc. could never all agree on your choice, hence voicemail will record many at your behest, I personally have moved to ogg vorbis ( sox supported) as anything that understands html5 can read it., some old sip phones still only read .wav though. Call .ogg the .wav of the future?

I’m talking about the “call recording format” option in Advanced Settings. I changed that to WAV. No ogg/mp3 option there. So no need to set a script to run.

Considering WAV49 is pretty space efficient and this method is really straight forward, what am I missing that makes this less ideal of a solution then a script calling SOX to convert to mp3, ogg, or whatever? This method I don’t have to bother updating mysql in a script file either.

If none of your clients complain that they can’t play wav49, then you are done.

Unlikely to be able to play that on many devices from my experience so check yours - and it can’t be converted to mp3 as well was the PCM encoded wav from my experience - i.e. if you are happy with that format great, but don’t count on it being suitable for format conversion later. The mp3 that result will be of poor quiality.

I’d just be setting it for call recording. We don’t send call recordings in emails or anything. They play fine in the Chrome web browser via FreePBX CDR reports, Call Recording Reports, and Asternic reports. They also play fine downloaded to a Windows 10 desktop PC and played through the default built-in “Groove Music” player. Also plays fine in VLC.

Interesting enough I have the same problem with the duration value in the Call Recordings Report when changing to other encoding. Even when I used the script w/ sox to convert to ogg. Probably need to update everything on the system to latest FreePBX release (14 I think) and if still persists submit a bug.

Does anyone know how to manually convert a wav to a WAV49 via command line?

I’m just trying to perform a quick size and quality comparison between mp3, ogg (default looks like q4), and wav49. So far it looks like wav49 is comparable.

Does this work in asterisk 15/freepbx 14?

The script gets as far as creating the mp3 successfully but the database never gets updated, nor does the file get moved to $wavpath.

My asterisk/freepbx/bash knowledge is insufficient to figure out how to fix this.

Help?

Thanks!


Edit, I think it’s a permission issue for running mysql. Asterisk/freepbx is installed under ubuntu which blocks the root account.

I assume this command is executed under the asterisk user?

If so, I tried adding the line

    asterisk ALL = NOPASSWD : /usr/bin/mysql

using visudo, but that didn’t help.

Problem solved! (ubuntu 18.x minimal server, 32bit).

The above permission fix was correct, however it’s placement is important as the permission file is executed top to bottom.

asterisk ALL = NOPASSWD : /usr/bin/mysql

Should be added at the bottom of the file.

I refused the mysql line by prefixing it with sudo and removing the -u root. End result looks like this and works!

sudo mysql  -s -D asteriskcdrdb -e "UPDATE cdr SET recordingfile = '$1.mp3' WHERE uniqueid = '$2'"

It seems during playback from the UI cdr page, the mp3 is converted to a low quality ogg file. However the downloaded mp3 sounds just as good as the original call.

Anyway to change the ui playback transcoding to either leave it as mp3 or transcode to wav?

Thanks again!

Does this work in freepbx 15?
i cant find “Post Call Recording Script” in Advanced settings

It’s there in 15. You may have to first enable Display Readonly Settings and Override Readonly Settings in order to see it.

Remember, using the PCRS on a really busy server can cause performance problems. Converting the files “en masse” is also a solution, as we discussed in this thread a couple of years ago.

copy that~thanks

thank u~i got it