NO JOY Sendmail And Sendmailmp3

Flash

New Member
Joined
Apr 24, 2018
Messages
11
Reaction score
2
I've had to customise the mailcmd in the voicemail.conf file to get it to work with my mail server.
This solved my issue, but now the attachments are .wav files, which some mobiles cannot open.

I can see sendmailmp3 could be used - but can you add the same flags as you would for sendmail?

e.g. sendmailmp3 -t -f [email protected] -v

(I ask becaues it didn't seem to work for me, but it may be for other reasons)

Many thanks
 

JoeOIVOV

Member
Joined
Sep 14, 2018
Messages
55
Reaction score
15
I've had to customise the mailcmd in the voicemail.conf file to get it to work with my mail server.
This solved my issue, but now the attachments are .wav files, which some mobiles cannot open.

I can see sendmailmp3 could be used - but can you add the same flags as you would for sendmail?

e.g. sendmailmp3 -t -f [email protected] -v

(I ask becaues it didn't seem to work for me, but it may be for other reasons)

Many thanks

Thank you for that mailcmd - Fixed the issue I've spent the morning trying to solve.
The default sendmailmp3 file is broken on the latest Raspbian release, no matter how long the voicemail it always sends a 268k mp3 file that shows up corrupt and cannot be played on any device.

To fix go into Settings>Voicemail Admin>Email Options and change the mailcmd from /usr/local/sbin/sendmailmp3 to sendmail -t and it sends a WAV file and works perfect. I can play WAV files on my phone and PC.

I'll spend some time to try and get MP3's working but thanks for the command fixed my issue.
 
Last edited:

JoeOIVOV

Member
Joined
Sep 14, 2018
Messages
55
Reaction score
15
Found the problem. I was missing an app called "Lame"

- run command apt install Lame
- go to Settings>Voicemail Admin>Email Config> and change Mail Command to /usr/local/sbin/sendmailmp3
- rm /usr/local/sbin/sendmailmp3 - to remove existing sendmailmp3 file in /usr/local/sbin
- nano /usr/local/sbin/sendmailmp3 - add the following to this file:

#! /bin/sh
# Asterisk voicemail attachment conversion script, including voice recognition
# Use Voice Recognition Engine provided by IBM Bluemix Sppech-to-Text API

# Revision history :
# 22/11/2010 - V1.0 - Creation by N. Bernaerts
# 07/02/2012 - V1.1 - Add handling of mails without attachment (thanks to Paul Thompson)
# 01/05/2012 - V1.2 - Use mktemp, pushd & popd
# 08/05/2012 - V1.3 - Change mp3 compression to CBR to solve some smartphone compatibility (thanks to Luca Mancino)
# 01/08/2012 - V1.4 - Add PATH definition to avoid any problem (thanks to Christopher Wolff)
# 01/06/2013 - V1.5 - Improved call quality of MP3
# 10/11/2014 - V1.6 - TB Sampson fix for iPhone playback too: http://nerd.bz/1vTN3Hq
# 12/03/2017 - V2.3 - modified for use with IBM Bluemix Speech-to-Text API (thanks to Jason Klein and Ward Mundy & Associates LLC)
# 01/17/2018 - V2.4 - added "echo -e" for proper newline treatment in messages (thanks Bill Simon)

# Special thanks: https://jrklein.com/2015/08/17/asterisk-voicemail-transcription-via-ibm-bluemix-speech-to-text-api/

# set credentials for IBM Bluemix Speech-to-Text API
# Obtain Bluemix credentials here: https://www.ibm.com/watson/developercloud/doc/common/getting-started-credentials.html
# 1. Create Bluemix account here: https://console.ng.bluemix.net/registration/?target=/catalog/?category=watson
# 2, Confirm registration by replying to email
# 3. Login to Bluemix: https://console.ng.bluemix.net/login?state=/catalog/?category=watson
# 4. Agree to T&C, name your organization, and name your space (STT)
# 5. Choose Watson Speech to Text service and click Create
# 6. When Speech to Text-kb opens, click Service Credentials tab
# 7. In Actions column, click View Credentials and copy your username and password
# 8. Insert deciphered Bluemix API username and password below:
# 9. Logout by clicking on image icon in upper right corner of dialog window
API_USERNAME="hidden"
API_PASSWORD="hidden"


# set PATH
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# save the current directory
pushd .

# create a temporary directory and cd to it
TMPDIR=$(mktemp -d)
cd $TMPDIR

# dump the stream to a temporary file
cat >> stream.org

# get the boundary
BOUNDARY=`grep "boundary=" stream.org | cut -d'"' -f 2`

# cut the file into parts
# stream.part - header before the boundary
# stream.part1 - header after the boundary
# stream.part2 - body of the message
# stream.part3 - attachment in base64 (WAV file)
# stream.part4 - footer of the message
awk '/'$BOUNDARY'/{i++}{print > "stream.part"i}' stream.org

# if mail is having no audio attachment (plain text)
PLAINTEXT=`cat stream.part1 | grep 'plain'`
if [ "$PLAINTEXT" != "" ]
then

# prepare to send the original stream
cat stream.org > stream.new

# else, if mail is having audio attachment
else

# cut the attachment into parts
# stream.part3.head - header of attachment
# stream.part3.wav.base64 - wav file of attachment (encoded base64)
sed '7,$d' stream.part3 > stream.part3.wav.head
sed '1,6d' stream.part3 > stream.part3.wav.base64

# convert the base64 file to a wav file
dos2unix -o stream.part3.wav.base64
base64 -di stream.part3.wav.base64 > stream.part3.wav

# convert wav file to mp3 file
# -b 24 is using CBR, giving better compatibility on smartphones (you can use -b 32 to increase quality)
# -V 2 is using VBR, a good compromise between quality and size for voice audio files
# lame -m m -b 64 stream.part3.wav stream.part3.mp3
# TB Sampson mod for iPhone AND Android playback support
lame --abr 24 -mm -h -c --resample 22.050 stream.part3.wav stream.part3.mp3
# convert back mp3 to base64 file
base64 stream.part3.mp3 > stream.part3.mp3.base64

# generate the new mp3 attachment header
# change Type: audio/x-wav to Type: audio/mpeg
# change name="msg----.wav" to name="msg----.mp3"
sed 's/x-wav/mpeg/g' stream.part3.wav.head | sed 's/.wav/.mp3/g' > stream.part3.mp3.head

CURL_OPTS=""
#API_USERNAME="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
#API_PASSWORD="XXXXXXXXXXXX"

# Send WAV to Watson Speech to Text API. Must use "Narrowband" (aka 8k) model since WAV is 8k sample.
curl -s $CURL_OPTS -k -u $API_USERNAME:$API_PASSWORD -X POST \
--limit-rate 40000 \
--header "Content-Type: audio/wav" \
--data-binary @stream.part3.wav \
"https://stream.watsonplatform.net/s...e?continuous=true&model=en-US_NarrowbandModel" 1>audio.txt

# Extract transcript results from JSON response
TRANSCRIPT=`cat audio.txt | grep transcript | sed 's#^.*"transcript": "##g' | sed 's# "$##g'`

# generate first part of mail body, converting it to LF only
mv stream.part stream.new
cat stream.part1 >> stream.new
cat stream.part2 >> stream.new
echo -e "\r\n\r\n Message contents: $TRANSCRIPT" >> stream.new
cat stream.part3.mp3.head >> stream.new
dos2unix -o stream.new

# append base64 mp3 to mail body, keeping CRLF
unix2dos -o stream.part3.mp3.base64
cat stream.part3.mp3.base64 >> stream.new

# append end of mail body, converting it to LF only
echo "" >> stream.tmp
echo "" >> stream.tmp
cat stream.part4 >> stream.tmp
dos2unix -o stream.tmp
cat stream.tmp >> stream.new

fi

# send the mail thru sendmail
cat stream.new | sendmail -t

# go back to original directory
popd

# remove all temporary files and temporary directory
rm -Rf $TMPDIR

- chmod +x /usr/local/sbin/sendmailmp3

After that the script works great to convert the WAV to MP3 which also works great. I noticed the quality of the VM is the same but the size of the MP3 is about 1/10th of a WAV file.
 

Members online

Forum statistics

Threads
25,811
Messages
167,759
Members
19,240
Latest member
nikko
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top