-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure Twilio to record voicemail and send it by email #6
Comments
How I Failed to Configure a Voicemail Using TwiML AloneStarting from a script as simple as possible to forward calls to my SIP endpoint, I first added a message, read by a friendly female robot using
A few notes:
This script handles correctly two out of three cases:
We would like to trigger the voicemail only for failed calls, not for successful calls. Unfortunately, there is no way in TwiML to make a distinction between a failed call and a successful one: When no When a URL is provided in the It is also possible to set a callback URL in the Lacking a separate |
Twimlets to the Rescue!After TwiML Bins, the next simplest option is Twimlets, a set of ready-made scripts developed and hosted by Twilio. We first need a Twimlet which checks whether the call failed or succeeded before it triggers the voicemail. To that end, we will use a little trick with the Forward Twimlet. That Twimlet is designed to call a regular phone number:
But we are forwarding the call to a SIP Phone Number, and thus we are only interested in the fallback part of the Twimlet. To skip the first part, we will set the
In addition, we will use the Voicemail Twimlet which seems to match our needs perfectly:
Optionally, it can also transcribe the audio recording to text, but after a few tests, I did not find this option very useful because the transcription always assumed an English speaker even when I called from a French number, and the transcription was far from accurate, even in English. For example:
I'll let you ponder what the original sentences where... At the end of the page for the Voicemail Twimlet, you find a form, the Twimlet Generator, which lets you build a URL with parameters to customize the behavior of the Twimlet: Fill in your email and set the Transcribe option to You get the resulting URL, in red, at the bottom of the generator:
Let's change the protocol from
If you leave the Message field empty, the default message will be played:
This is a bit dry. You can customize this message, adding your name or your phone number. Your message can span several lines, for example:
Type your text in the Message field and you get a more complicated URL: Change it to
Sadly, it is not possible to select the If you want to play a message in a different language or in your own voice, you will need to play an audio recording instead. In the next three sections below, I will describe:
You can skip these three sections if you are using the text-to-speech conversion, and jump directly to the section after, Redirecting Missed Calls to Voicemail, which describes how to chain our TwiML script which handles incoming calls with the Forward Twimlet and the Voicemail Twimlet. |
Recording Your Voicemail GreetingHere I am using Audacity to record the greeting message in WAV format. Alternatively, you can use any audio recorder capable of saving files in WAV or AIFF format. Twilio also supports playing files in MP3 format, but these are already compressed, and their conversion to the low bitrate format actually played on telephone networks is slower and may yield poor results. Thus Twilio recommends to record at 8kbps in a lossless format. I do not think that they actually mean 8kbps uncompressed, but rather 8kHz with a depth of 8 bits which gives 64kbps uncompressed:
When you first open Audacity, there are no audio tracks yet: In the top part of the window, you can select the Audio Host and Recording Device, e.g. the Built-In Microphone. If your computer does not have a built-in microphone, make sure that you plug one in before recording. Next on the right on the same line, reduce the number of channels from 2 (Stereo) to 1 (Mono): Then at the bottom-left of the window, change the Project Rate from 44100 Hz to 8000 Hz: Write down or make a mental note of what you are going to say in your greeting, and say it out loud a few times, trying to articulate as much of possible. You can safely exaggerate a lot before you actually over-articulate. If you want to sound more natural, you can put the photograph of a person in front of you. Imagine a first sentence spoken by that person, then look at the person in the photograph while recording your greeting, as if you were answering them. Make sure that you do not leave long pauses before you announce that you are not available, however, or a caller might start speaking, thinking that you are actually on the line. When you are ready to record, you should first check the recording level. The input level at the top of the window bears the instruction "Click to Start Monitoring". Click it and start talking; the recording level is shown as a green bar which grows from left to right. The maximum level reached is shown as a blue line: Look at the meter as you repeat your greeting. If you speak louder and louder, the green bar changes to yellow (high but ok), orange (dangerously high) and red (too high, sound will be distorted). You want the green bar to grow as much as possible without getting into the red, to capture the whole dynamics of your voice without clipping. Instead of speaking louder, speak normally and adjust the recording volume on the left of the window. It starts at 0.5, which is typically too low: Audacity manual recommends to aim for a maximum level of approximately -6 dB. To reach this level in my case, I moved the recording volume close to 1.0: You can now press the It can be cumbersome to look for the buttons to start/end the recording while you are focusing on your performance. You can use keyboard shortcuts instead: On my computer, there was a little latency before the actual recording started. If it is your case as well, do not speak immediately after hitting Record, but wait one or two seconds before you start to speak. If you are not satisfied with a recording, press the Once you are satisfied with a recording, start by saving the project to keep a copy of the original: then enter a name for your project: and click the The project name is now displayed in the title bar at the top of the window. Press the You can trim silent parts at the start and end of the recording, which often contain a bit of noise related to the manipulations to start and end the recording. You can also reduce long breaks in the middle of the recording. A period of silence appears as a flat line in the waveform visualization. Select a range with the mouse, then press You can move the cursor back to the beginning of the track with the mouse or by pressing the The infamous beep which signals the beginning of the recording will be played right after the end of your greeting, without any pause. I would rather leave a slight delay, to let the caller decide whether to leave a message or hang up before the beep. After trimming the end of the recording to remove the noise, you may append one to two seconds of silence at the end of the recording. Move the cursor to the end of the recording with a click or by pressing the Select the duration of silence; I chose 1.5 seconds: The click the When you are done editing, save the project with a new name, e.g. "Voice-Mail-EDIT", to preserve the unedited original. You can now export the recording to WAV: The default is a WAV format with 16 bits of depth. But we want 8 bits of depth. Select Other uncompressed files as File format. You can then select further file format options:
Strangely enough, the file extension gets changed to aiff, but the file will actually be saved with the wav extension. You can customize the file name and location, then click the You can leave all the fields blank or, optionally, set your name as Artist Name, give a Track Title, the current Year, the Genre, and so on: |
Hosting the Audio File as an Asset on TwilioThe Voicemail Twimlet can play audio files accessible from any URL. If you have your own Web server, you may host it there. I find it more convenient to keep everything in the same place though, and to let Twilio host the audio file for the greeting as well.
Do not check the box to make the asset private, which would prevent the Voicemail Twimlet from accessing it:
while
|
Using the Voicemail Twimlet with an Audio GreetingWe can now configure the Voicemail Twimlet to play our recorded greeting instead of a synthesized message.
We will now set this URL to the |
Redirecting Missed Calls to VoicemailAt this point, you have a URL for the Voicemail Twimlet with your custom configuration, either using a text message in English or a link to an audio greeting that you recorded yourself.
Note: If you forgot to replace the Do not save the invalid TwiML, but cancel and check that the
|
Managing VoicemailsYou can find the list of recorded voicemails in your Twilio dashboard:
Sadly, there is no easy option to delete all these recordings at once. Fortunately, Twilio will store up to 10,000 minutes of voicemail for free (that's more than 6 days!), and only charges $0.0005/minute per month beyond that point. If you only wish to delete a few voicemail recordings, you can do it one by one:
Otherwise, you can use the Twilio API to list and delete voicemail recordings. Using the API, you can list up to 10,000 recordings in a single request, then delete them one by one. You can find an example script in PHP and Python in this blog post. I would personally write a shell script instead, using #!/bin/sh
# Delete all voicemail recordings from your Twilio account
#
# Note:
# a single run of this script will delete up to 10,000 voicemails.
#
# Requires:
# * curl - transfer a URL
# * jq - Command-line JSON processor
#
cd "$(dirname "$0")"
accountSID='' # REQUIRED
authToken='' # REQUIRED
test -f ./auth.sh && . ./auth.sh
if test -z "$accountSID" -o -z "$authToken"
then
cat <<EOF >&2
accountSID and authToken must be set at the top of this script
or in a file called auth.sh in the same directory as this script.
They can be found in your Twilio dashboard:
https://www.twilio.com/console
EOF
exit 1
fi
if test -z "$(which curl)" -o -z "$(which jq)"
then
cat <<EOF >&2
curl and jq are required.
curl: https://curl.haxx.se/
jq: https://stedolan.github.io/jq/
EOF
exit 2
fi
api="https://api.twilio.com/2010-04-01/Accounts/$accountSID"
auth="$accountSID:$authToken"
curl "$api/Recordings.json" -u "$auth" -s |
jq '.recordings[] | .sid' --raw-output |
while read -r recordingSID
do
echo "Delete recording $recordingSID..."
curl -X DELETE "$api/Recordings/$recordingSID.json" -u "$auth" -s
done
echo 'Done.' |
I enhanced the recording of the greeting and introduced the Forward Twimlet between the TwiML <Dial> and the Voicemail Twimlet.
You may leave your comments below. |
When the software phone is closed on my computer, or when I am away and unable to answer a call, I wish to direct the caller to voicemail.
A notification of the call including the date/time, the phone number of the caller and a link to the recording should then be sent to me by email.
The text was updated successfully, but these errors were encountered: