请帮助我,为什么当我从AGI运行它时,Sphinx给我空$结果,但是当我从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 $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;
}
}
?>
答案 0 :(得分:0)
问题在于accoustic files文件夹权限。只需将其移至/ home / asterisk并运行
chown -R asterisk:asterisk /home/asterisk