Php 将星号拨号计划中的单词转换为数字

Php 将星号拨号计划中的单词转换为数字,php,perl,asterisk,agi,Php,Perl,Asterisk,Agi,我花了三个星期的时间试着让它起作用。我想使用github上提供的googletts.agi脚本从asterisk进行语音拨号。这是可行的,但问题是谷歌有时会在“话语”变量中返回一个单词而不是一个数字,比如18004633339可能会返回“180046 tree nite”或“1800 force 6 tree 339”等 https://github.com/zaf/asterisk-speech-recog 下面的链接有一个将单词转换为数字的脚本 这是我的拨号计划 exten =>

我花了三个星期的时间试着让它起作用。我想使用github上提供的googletts.agi脚本从asterisk进行语音拨号。这是可行的,但问题是谷歌有时会在“话语”变量中返回一个单词而不是一个数字,比如18004633339可能会返回“180046 tree nite”或“1800 force 6 tree 339”等

https://github.com/zaf/asterisk-speech-recog

下面的链接有一个将单词转换为数字的脚本

这是我的拨号计划

exten => 2255,1,Answer()
exten => 2255,n,Wait(1)
;exten => 2255,n,flite("Say the number you wish to call. Then press the pound key.")
exten => 2255,n,Espeak("Say the number you wish to call. Then press the pound key.")
exten => 2255,n(record),agi(speech-recog.agi,en-US)
exten => 2255,n,Noop(= Script returned: ${status} , ${id} , ${confidence},            ${utterance} =)
exten => 2256,6,Set(NUM2CALL=${utterance})
此处需要代码,该代码将接受${outreance}或NUM2CALL变量,并在其中有单词时将其修复为星号可以拨打的正确号码

exten => 2255,n,SayDigits("${NUM2CALL2}")
exten => 2255,n,Background(vm-star-cancel)
exten => 2255,n,Background(vm-tocallnum)
exten => 2255,n,Read(PROCEED,beep,1)                                        
exten => 2255,n,GotoIf($["foo${PROCEED}" = "foo1"]?15:16)
exten => 2255,15,Goto(outbound-allroutes,${NUM2CALL2},1)
exten => 2255,16,hangup
我在想,如果我可以添加到字典数组中,我最终将拥有一个非常精确的声控拨号器。我花了4天的时间测试tropo ASR,它对于一位数非常准确,但是对于多位数的精度很快就会下降。提前感谢您的帮助。我将把完成的脚本作为一个项目发布到github上。我尝试使用pocketphinx,也尝试了TIDIGITS语法和模型,但这比pocketsphinx默认字典更糟糕,后者给出了类似的问题。

使用,您可以调用函数,即,
将单词转换为数字
和, 在执行AGI脚本后,可以在拨号盘中使用

在计划中

exten => 2256,6,Set(NUM2CALL=${utterance})
exten => 2256,n,AGI(/home/asterisk/agi-bin/words_agi.php);
和AGI脚本:

#!/usr/bin/php -q
<?php
set_time_limit(30);
require_once 'phpagi.php';

// replace this function with yours
function convert_word_to_number($word) {
   $words = array(
     'tree',
     'too',
      // ...
    );
    $numbers = array(3,2)
   // replace words with numbers - example only
   $num = str_replace($words, $numbers, $word);
   return $num;
}

$agi = new AGI();
$word = $agi->get_variable("NUM2CALL"); 
$spokenNumber = convert_word_to_number($word);
$agi->set_variable("NUM2CALL", $spokenNumber);
#/usr/bin/php-q

非常感谢。取得了一些进展,但是变量没有进入数组。缺少了一些内容。非常感谢。取得了一些进展,但变量没有进入数组,缺少了一些内容。这是日志。如何设置变量?我在日志中看到$num,而不是$num的预期值。我完全按照您在这里给我的设置。必须在数字数组行的末尾添加“;”。agi调试日志似乎显示了传递到脚本中的变量,但是字符串替换函数似乎没有运行,还必须删除空格,但我想我可以找到答案$num应该是实际变量,但这就是正在发生的。更新字符串替换没有发生,我将继续尝试。Asterisk 10内置了这个函数,现在STRREPLACE添加了一个函数string的特性,试图让它也工作起来。