Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Asterisk AGI script that makes use of Microsoft Translator text to speech service.
Perl
tag: v0.3

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
cli
COPYING
ChangeLog
README
authors
mstts.agi

README

=============================================
      Microsoft TTS script for Asterisk
=============================================

This script makes use of Microsoft Translator text to speech service
in order to redner text to speech and play it back to the user.
It supports a variety of different languages.

------------
Requirements
------------
Perl         The Perl Programming Language
perl-libwww  The World-Wide Web library for Perl
sox          Sound eXchange, sound processing program
mpg123       MPEG Audio Player and decoder
Internet access in order to contact MS and get the voice data.

To use this script you have to subscribe to the Microsoft Translator API on Azure Marketplace:
https://datamarket.azure.com/developer/applications/
and register your application with Azure DataMarket:
https://datamarket.azure.com/developer/applications/

------------
Installation
------------
To install copy mstts.agi to your agi-bin directory.
Usually this is /var/lib/asterisk/agi-bin/
To make sure check your /etc/asterisk/asterisk.conf file

-----
Usage
-----
agi(mstts.agi,"text",[language],[intkey],[speed]): This will invoke the Microsoft TTS
engine, render the text string to speech and play it back to the user.
If 'intkey' is set the script will wait for user input. Any given interrupt keys will
cause the playback to immediately terminate and the dialplan to proceed to the
matching extension (this is mainly for use in IVR, see README for examples).
If 'speed' is set the speech rate is altered by that factor.

The script contacts MS TTS service in order to get the voice data
which then stores in a local cache (by default /tmp/) for future use.
Parameters like default language, enabling or disabling caching and cache dir
can be set up by editing the script.

--------
Examples
--------
sample dialplan code for your extensions.conf

;MSTTS Demo
;PLayback messages to user

exten => 1234,1,Answer()
    ;;Play mesage in English:
exten => 1234,n,agi(mstts.agi,"This is a simple microsoft text to speech test in english.",en)
    ;;Play message in Spanish
exten => 1234,n,agi(mstts.agi,"Esta es una simple prueba en español.",es)
    ;;Play message in Japanese
exten => 1234,n,agi(mstts.agi,"これは、日本の簡単なテストです。良い一日を。",ja)

;A simple dynamic IVR using MSTTS

[my_ivr]
exten => s,1,Answer()
exten => s,n,Set(TIMEOUT(digit)=5)
exten => s,n,agi(mstts.agi,"Welcome to my small interactive voice response menu.",en)
    ;;Wait for digit:
exten => s,n(start),agi(mstts.agi,"Please dial a digit.",en,any)
exten => s,n,WaitExten()

    ;;PLayback the name of the digit and wait for another one:
exten => _X,1,agi(mstts.agi,"You just pressed ${EXTEN}. Try another one please.",en,any)
exten => _X,n,WaitExten()

exten => i,1,agi(mstts.agi,"Invalid extension.",en)
exten => i,n,goto(s,start)

exten => t,1,agi(mstts.agi,"Request timed out.",en)
exten => t,n,goto(s,start)

exten => h,1,Hangup()

-------------------
Supported Languages
-------------------
ca,     ca-es,    da,    da-dk,
de,     de-de,    en,    en-au,
en-ca,  en-gb,    en-in, en-us,
es,     es-es,    es-mx, fi,
fi-fi,  fr,       fr-ca, fr-fr,
it,     it-it,    ja,    ja-jp,
ko,     ko-kr,    nb-no, nl,
nl-nl,  no,       pl,    pl-pl,
pt,     pt-br,    pt-pt, ru,
ru-ru,  sv,       sv-se, zh-chs,
zh-cht, zh-cn,    zh-hk, zh-tw

-------
License
-------
The MStts script for asterisk is distributed under the GNU General Public
License v2. See COPYING for details.

--------
Homepage
--------
http://zaf.github.com/asterisk-mstts/

---------------
API Description
---------------

Request
-------
GET    http://api.microsofttranslator.com/V2/Http.svc/Speak

Parameters
----------
appId
 Required. If the Authorization header is used, leave the appid field empty else
 a string containing "Bearer" + " " + access token.

text
 Required. A string containing a sentence or sentences of the specified language to be
 spoken for the wave stream.

language
 Required. A string representing the supported language code to speak the text in.
 The code must be present in the list of codes returned from the method GetLanguagesForSpeak.

format
 Optional. A string specifying the content-type ID. Currently, "audio/wav" and
 "audio/mp3" are available. The default value is "audio/wav".

options
 Optional. A string specifying the quality of the audio signals. Currently, "MaxQuality"
 and "MinSize" are available. With "MaxQuality", you can get the voice(s) with the highest
 quality, and with "MinSize", you can get the voices with the smallest size. If no value
 is provided, we default to "MinSize".

Response
--------
Returns a wave or mp3 stream of the passed-in text being spoken in the desired language.
Something went wrong with that request. Please try again.