从 AGI 运行时为空 var(但不从 bash 中为空)



请帮助我,为什么类 Sphinx 在我从 AGI 运行时给我空$result,但当我从 bash 运行它时,给我不空$result。此外,类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 $resultn";
return $result;
?>

狮身人面像.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;
    }
}
?>

问题出在声音文件文件夹权限上。刚刚将其移动到/主页/星号并运行

chown -R asterisk:asterisk /home/asterisk

最新更新