dpb_4431 2016-06-10 12:39
浏览 38
已采纳

从AGI运行时为空变量(但从bash不是空的)

Please help me, why class Sphinx gives me empty $result when I run it from AGI, but gives me not empty $result, when I run it from bash. Also class Yandex gives not empty correct $result with both situations. Initial voice_rec.php

#!/usr/bin/php5
<?php

$start = microtime(true);

spl_autoload_register(function ($class) {
    include 'Classes/' . $class . '.php';
});

$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');
$stdlog = fopen('my_agi.log', 'w');


$filename = $argv[1];
$table = $argv[2];
$number = $argv[3];


$VoiceClass = new Sphinx();
$result = $VoiceClass->voice2Text($filename);

echo "VERBOSE $result
";

return $result;
?>

Sphinx.php

<?php

/**
 *
 */
class Sphinx
{
    public $dict, $grammar;
    function __construct($dict = "/home/asterisk/baltartek/cmusphinx/dict.dic", $grammar = "/home/asterisk/baltartek/cmusphinx/grammar.jsgf")
    {
        $this->dict = $dict;
        $this->grammar = $grammar;
    }

    public function voice2Text($filename)
    {
        $command = "pocketsphinx_continuous -samprate 8000 -logfn /dev/null -hmm /root/zero_ru_cont_8k_v3/zero_ru.cd_cont_4000 ".
            "-dict ".$this->dict." -jsgf ".$this->grammar." -infile $filename";

        exec($command, $ans);


        $result = implode("",$ans);

        return $result;

    }

}
?>

Yandex.php (which is working well both in AGI and Bash)

<?php

/**
* 
*/
class Yandex
{
    public $key = '****';
    public $topic = "freeform";
    public $lang = "ru-RU";
    public $uuid;

    function __construct()
    {
        $this->uuid = md5(time());
    }

    public function voice2Text($filename)
    {
        $cmd = exec('curl --silent -F "Content-Type=audio/x-wav" -F "audio=@'.$filename.'" asr.yandex.net/asr_xml\?key='.$this->key.'\&uuid='.$this->uuid .'\&topic='.$this->topic.'\&lang='.$this->lang, $xml); 


        $res_xml = implode($xml);
        if (preg_match('!<variant .*?>(.*)</variant>!si', $res_xml, $arr)) $voice_text = $arr[1];
            else $voice_text='';


        $result = strtolower($res_xml);


        return $result;
    }

}
?>
  • 写回答

1条回答 默认 最新

  • dtgta48604 2016-06-10 13:52
    关注

    The problem was in accoustic files folder permissions. Just moved it to /home/asterisk and run

    chown -R asterisk:asterisk /home/asterisk
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题