In this article, we will try to explain the implementation of Google Speech Recognition with asterisk 15.  We will start from installation of Asterisk 15.


The first step we must to do, is install the Development Packages :

# yum -y groupinstall 'Development Tools'

The next step is install the dependencies for Asterisk 15.

# yum install wget ssh ncurses ncurses-devel uuid uuid-devel libuuid-devel jansson-devel libxml2-devel sqlite-devel

Now, we can move to Home and download the the version number 15 of Asterisk:

# cd ~
# wget

Now we shall move to /usr/src, decompress the tarball and move to the new directory:

# cd /usr/src
# tar zxvf ~/asterisk-15-current.tar.gz
# cd asterisk-15*

Now execute the script configure and after make to generate the menu selection.

# ./configure
# make menuselect

Then, we shall execute the followings commands. If we do not have a mandatory  Asterisk’s dependency the process would let us know, so pay attention to de STDERR.

# make
# make install
# make config
# make install-logrotate

If we want to generate files samples we should execute the following command:

# make samples

If you have any problem with Asterisk when you try to start it, you can try to deactivate SELinux  and Firewall and try again. Then we shall restart the service:

# service asterisk restart

To open de CLI, execute:

# asterisk -cvvvvvv

We shall user the Zaf’s script for the Google Cloud Speech API, we can download it from here

The next step is install the script’s dependencies, so we have to download the followings packets:

# yum install flac flac-devel perl perl-JSON perl-libwww-perl.noarch perl-LWP-Protocol-https perl-Crypt-SSLeay

We should move the file speech-recog.agi to the path for the AGI bin files, by default /var/lib/asterisk/agi-bin, if this directory does not exists, it must be declared in /etc/asterisk/asterisk.conf file.

As an example we will create the context google-asr, inside of /etc/asterisk/extensions.conf 


exten => 666,1,Answer(); 
same => n,agi(speech-recog.agi,en,2,#);
same => n,Verbose(1,You said: ${utterance}); 
same => n,Verbose(1,The probability to be correct: ${confidence});
same => n,Verbose(1,The numbers of characters is: ${LEN(${utterance})});
same => n,Hangup();

Keep in mind this context must be added to the main context for our sip users in the sip.conf file.


If we have another context as main, we can include the google-asr context in the main one as i show below:

include => google-asr;

Now, we must do the two most important steps:

  1. Generate our key for the Google Cloud API
  2. Activate the billing in Google Cloud
  3. Insert our key in the speech-recog.agi file

For the first step you have to do the following:

  1. Go to Google Cloud Console:
  2. If we do not have any  project, we must create a new one, after that we shall search “Google Cloud Speech API“, select the API and enable it.
google asr with asterisk 15
google asr with asterisk 15

3. At that moment a popup window will come out, letting know us we have to enable the billing in order to use the API.

4. When you enable the billing, on the left side you will see a key (Credentials). Click it and after ‘Create credentials’ –> ‘API Key’ –> Copy the API Key, and close.

In order to check we do not have any problem with the billing setting in our project we can execute the following command:

$ curl$KEY -X POST -d '{}'

In the STDOUT you should not see any problem related with the billing settings.

Now we should edit the file speech-recog.agi and add our  API Key to the variable $key:

my $key = “”; //it should be like my $key = “AIzaSyB**the rest**

When everything is ready from our softphone if call to the 666 extension we should listen a BEEP sound, if it is like that, then we can say something.