Asterisk, and other worldly endeavours.

A blog by Leif Madsen

Manually mixing files created by MixMonitor()


So last night I did a system update between 11:30pm and 5:00am. One of the things I forgot to do when I was moving to the new system was to install sox so that MixMonitor() could mix the -in and -out files automatically for me. I still had the recordings, but I needed to get them mixed. I first installed sox so that all new recorded files would be mixed for me. I also needed the soxmix application to mix the files together for me. πŸ™‚

I created a little bash script to do this for me. Some of my files had different numbers of fields, but I think the common format for Asterisk is 5 fields (separate with a hyphen) followed by either -in.wav or -out.wav. The following script takes the files in the /var/spool/asterisk/monitor/merge/ directory, and mixes them together to a single file, then places them in the /var/spool/asterisk/monitor/ directory.

#!/bin/bash

for NAME in $(find /var/spool/asterisk/monitor/merge/ -maxdepth 1 -type f | cut -d "/" -f7 | cut -d "-" -f1-5)
#                                                                                         fields we want  ^^^
do
        IN=$NAME-in.wav
        OUT=$NAME-out.wav
        MERGE=$NAME.wav
        MERGE_PATH=/var/spool/asterisk/monitor/merge
        WRITE_PATH=/var/spool/asterisk/monitor

        if [ -e $MERGE_PATH/$IN -a -e $MERGE_PATH/$OUT ]
        then
                echo "Both IN and OUT files exist. Creating $MERGE"
                soxmix $MERGE_PATH/$IN $MERGE_PATH/$OUT $WRITE_PATH/$MERGE
                mv $MERGE_PATH/$IN $MERGE_PATH/done/
                mv $MERGE_PATH/$OUT $MERGE_PATH/done/
        else
                echo "Skipping the creating of $MERGE due to IN and OUT not being found"
        fi
        echo ""
done

Advertisements

Written by Leif Madsen

2009/06/30 at 1:19 pm

3 Responses

Subscribe to comments with RSS.

  1. Thanks – this script was very helpful. In our instance, the file names had seven fields that needed to be preserved, and we also wanted to preserve order, so I modified the find line to read:

    for NAME in $(find /var/spool/asterisk/monitor/merge/ -maxdepth 1 -type f | cut -d “/” -f7 | cut -d “-” -f1-7 | sort)

    Today became a very good day as a result of this script πŸ™‚

    Andrew Yager

    2010/03/19 at 7:44 pm

  2. Hi

    Thanks for your blog.But our scenario is little complected.We are
    using attended transfer(using *2) for transferring a call to external number.So we are getting recordings of all phases of transfer as 2 files.There name is different since there interaction id is different .So I think above script will not work for us. So is there any way to merge these files? Only similarity between these 2 files are the time stamp.We are using ‘audio inherit’ function in dial plan. Do you have any idea over this???.

    Hans Emmanuel

    2010/08/10 at 4:43 am

    • That certainly is a more complicated scenario. While I don’t have the time right now to develop a solution for you, I can tell you why you get two separate files, and perhaps that will let you develop something clever in your dialplan to keep track of files and merge them manually at hang up.

      The reason you get two different files, is because when the first call comes in, you’re executing dialplan that triggers MixMonitor(), and that recording is now associated with the incoming caller:

      A ———–> B
      ^
      Recording Follows (file #1)

      Now when B decides to do an attended transfer to C, we get this scenario.

      B ———–> C
      ^
      Recording Follows (file #2)

      The problem is that these are two entirely separate calls that have absolutely no relationship with each other. This is what makes the solution complicated, because you essentially have to create a state machine that can analyze the data after the call and combine the recordings.

      The solution would involve something that could analyze some sort of data (CDR data, custom data you’ve written, etc…) after all the calls were done, and realize that A called B, that B called C, and that B then performed the transfer of A to C.

      A —-xfer—–> C
      ^ Recording Follows (file #1)

      The other side to this is that during the transfer of A –> C from phone B, is that if you wanted to perform control of the recordings, it’s very difficult (again, some sort of state machine would be necessary, and I haven’t developed anything like this) to do this. The recording is held against channel A, and when the transfer occurs, the dialplan doesn’t get executed (because typically this is done via a SIP transfer using a button on the SIP device).

      Anyways, hopefully that at least clears up why the solution you are looking for is not trivial πŸ™‚

      Leif Madsen

      2010/08/10 at 6:36 am


Comments are closed.

%d bloggers like this: