Fork me on GitHub

Text translation for Asterisk

Text translation and language detection for Asterisk using Microsoft Translator API.

This script makes use of Microsoft Translator API to translate text strings and return them as channel variables. See README for a complete list of supported languages.

Dependencies

Perl: The Perl Programming Language
perl-libwww: The World-Wide Web library for Perl
Internet access in order to contact Microsoft and get the language data.

In order to use this script you have to subscribe to the Microsoft Translator API on Azure Marketplace
Existing Bing API Keys from Microsoft still work but they are considered deprecated and this method is no longer supported.

Install

To install copy mstranslate.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(mstranslate.agi,"text",[target language],[source language]): The text string will be send to Microsoft for translation to target language. The translated text will be stored as a channel variable named 'mstranslation'. The setting of source language is optional, if not set the tranlator engine will try to auto detect it. If both target language and source language are omitted the script performs language detection on the given text string and returns the two-character language code as the value of the channel variable 'mslang'.

Asterisk dialplan examples:

;Translate a text string from english to french:
exten => 1234,1,agi(mstranslate.agi,"This is some random text.",fr)
exten => 1234,n,Verbose(1,Translated text: ${mstranslation})

;Translate from greek to german:
exten => 1234,1,agi(mstranslate.agi,"Αυτό είναι ένα απλό τέστ στα ελληνικά.",de)
exten => 1234,n,Verbose(1,Translated text: ${mstranslation})

;Translate from japanese to english:
exten => 1234,1,agi(mstranslate.agi,"これは、日本の簡単なテストです。良い一日を。",en)
exten => 1234,n,Verbose(1,Translated text: ${mstranslation})

;Translate string to many languages:
exten => 1235,1,Set(MYTEXT="This is some random text for translation.")
exten => 1235,n,agi(mstranslate.agi,"${MYTEXT}",it)
exten => 1235,n,Verbose(1,In Italian: ${mstranslation})

exten => 1235,n,agi(mstranslate.agi,"${MYTEXT}",fr)
exten => 1235,n,Verbose(1,In French: ${mstranslation})

exten => 1235,n,agi(mstranslate.agi,"${MYTEXT}",ja)
exten => 1235,n,Verbose(1,In Japanese: ${mstranslation})

exten => 1235,n,agi(mstranslate.agi,"${MYTEXT}",es)
exten => 1235,n,Verbose(1,In Spanish: ${mstranslation})

;Detect text language:
exten => 1236,1,Set(MYTEXT="This is some random text for detection.")
exten => 1236,n,agi(mstranslate.agi,"${MYTEXT}")
exten => 1236,n,Verbose(1,Detected language: ${mslang})

License

The mstranslate script for asterisk is distributed under the GNU General Public License v2.

Authors

Lefteris Zafiris (zaf.000@gmail.com)

Download

You can get the latest stable version here.
Develompent snapshots are available in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/zaf/asterisk-mstranslate

Links

Speech recognition for asterisk
GoogleTTS text to speech script for asterisk
Text translation using Google Translate API for Asterisk
Speech synthesis using Microsoft Translator API for Asterisk
Asterisk Flite text to speech module
Asterisk e-Speak text to speech module