The <GetSpeech> element collects caller voice and try to translate to text using a speech recognition engine. When the interpretation is done, Plivo submits that data to the provided ‘action’ URL in an HTTP GET or POST request.

If no voice input is received before timeout, <GetSpeech> falls through to the next element.

You may optionally nest <Speak>, <Play> and <Wait>elements within a <GetSpeech> element while waiting for voice input. This allows you to read menu options to the caller while letting them say speech at any time.

Element Attributes

The <GetSpeech> element supports the following attributes that modify its behavior:

Attribute Name Allowed Values Default Value
engine Speech engine to use pocketsphinx
grammar Grammar file to use none
action absolute URL none
timeout positive integer 5 seconds
playBeep true, false false

Plivo will pass the following parameters to the ‘action’ URL once the voice input has been captured:

Parameter Description
Grammar Grammar used for speech recognition.
Mode Speech mode.
SpeechResult The interpreted text.
Confidence Score of interpretation.
If “-1″, intepretation failed.
If 99, it’s really good.

About speech engine and grammar file

Supported engine

Currently, only pocketsphinx is supported.

Grammar files

You must create your own grammar files (JSGF v1.04 format) and put them in your freeswitch install directory (eg. /usr/local/freeswitch/grammar/).

See also

For example :

  • Download pizza_yesno grammar file : pizza_yesno.gram
  • Copy pizza_yesno.gram to /usr/local/freeswitch/grammar/


Example 1: Action/method and nested <Speak> or <Play> element

After the caller say something, Plivo sends him in a request to the ‘action’ URL. We also add a nested <Speak> element. This means that voice input can be gathered at any time during <Speak>.

<?xml version="1.0" encoding="UTF-8"?>
    <GetSpeech action="" method="GET" engine="pocketsphinx" grammar="pizza_yesno" timeout="20">
            Do you want a pizza ? 
    <Speak>Input not received. Bye bye!</Speak>
  • If <GetSpeech> engine recognized voice input (yes or no, …), it will submit the result to action URL.
  • If <GetSpeech> tag times out without voice input, the <GetSpeech> element will exit without submitting. Plivo will then process the next element in the document, which in this case is a <Speak> element which informs the caller that no input was received.

1 Response » to “Element <GetSpeech>”

Leave a Reply