Misc. Dialplan Tools play and detect speech

From FreeSWITCH Wiki
Jump to: navigation, search

Contents

Description

Play while doing speech recognition. Result is stored in the detect_speech_result channel variable.

Usage

<file> detect:<engine> {param1=val1,param2=val2}<grammar>

Parameters

  • file = file to play. See playback for details.
  • engine = speech recognition module. e.g. unimrcp
  • {param1=val1} = optional speech recognition parameters. This is specific to the speech recognition module used.
  • grammar = grammar may be inline:, builtin:, session:, a URL, a filename, etc.

Examples

This example demonstrates using TTS and speech recognition with mod_unimrcp.

<extension name="play_and_detect_speech example">
  <condition field="destination_number" expression="^(1888)$">
    <action application="set" data="tts_engine=unimrcp"/>
    <action application="set" data="tts_voice=donna"/>
    <action application="play_and_detect_speech" data="say:please say yes or no. please say no or yes. please say something! detect:unimrcp {start-input-timers=false,no-input-timeout=5000,recognition-timeout=5000}builtin:grammar/boolean?language=en-US;y=1;n=2"/> 
    <action application="log" data="CRIT ${detect_speech_result}"/>
  </condition>
</extension>

This example demonstrates playing a wav file and speech recognition with mod_unimrcp. Note: There is no space between wav and detect. As of 25 Apr 2012, any amount of whitespace is allowed between the wav file and "detect:".

<extension name="play_and_detect_speech example">
  <condition field="destination_number" expression="^(1888)$">
    <action application="set" data="tts_engine=unimrcp"/>
    <action application="set" data="tts_voice=donna"/>
    <action application="play_and_detect_speech" data="ivr/say_yes_or_no.wavdetect:unimrcp {start-input-timers=false,no-input-timeout=5000,recognition-timeout=5000}builtin:grammar/boolean?language=en-US;y=1;n=2"/> 
    <action application="log" data="CRIT ${detect_speech_result}"/>
  </condition>

Lua

This example Lua script uses mod_unimrcp and Lumenvox

session:answer()
session:sleep(1000)

-- MRCP ASR and TTS - module picks grammar name
session:execute("play_and_detect_speech","say:unimrcp:Chris:What is your phone number? detect:unimrcp {start-input-timers=false,define-grammar=true,no-input-timeout=5000}builtin:grammar/phone")
local xml = session:getVariable('detect_speech_result')
if xml ~= nil then
        freeswitch.consoleLog("INFO", xml .."\n")
else
        freeswitch.consoleLog("INFO", "No result!\n")
end

-- MRCP ASR and TTS - define the grammar name
session:execute("play_and_detect_speech","say:unimrcp:Chris:What is your phone number? detect:unimrcp {name=12345,start-input-timers=false,define-grammar=true,no-input-timeout=5000}builtin:grammar/phone")
local xml = session:getVariable('detect_speech_result')
if xml ~= nil then
        freeswitch.consoleLog("INFO", xml .."\n")
else
        freeswitch.consoleLog("INFO", "No result!\n")
end

-- Repeat, using cached grammar on session (without DEFINE-GRAMMAR).  ASR sessions are re-used and
-- params are sticky so name must be cleared and define-grammar must be set back to false.
session:execute("play_and_detect_speech","say:unimrcp:Chris:What is your phone number? detect:unimrcp {name=,start-input-timers=false,no-input-timeout=5000,define-grammar=false}session:12345")
local xml = session:getVariable('detect_speech_result')
if xml ~= nil then
        freeswitch.consoleLog("INFO", xml .."\n")
else
        freeswitch.consoleLog("INFO", "No result!\n")
end

session:hangup()

</extension>

See Also