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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题