当来自 AGI 运行 时为空 var(但来自 bash 时不为空)

Empty var when run from AGI (but not empty from bash)

请帮助我,为什么 class 当我从 AGI 运行 Sphinx 给我空的 $result,而当我 运行 它从 bash。另外 class Yandex 在这两种情况下都给出了不为空的正确 $result。 初始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\n";

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(在 AGI 和 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;
    }

}
?>

问题出在acoustic files文件夹权限上。刚刚将其移至 /home/asterisk 和 运行

chown -R asterisk:asterisk /home/asterisk