0
請幫助我,爲什麼當我從AGI運行它時,Sphinx類爲我提供空的$結果,但是當我從bash運行它時,不會給出空的$結果。在這兩種情況下,類Yandex也不會給出空的正確$結果。 初始voice_rec.php當從AGI運行時(但不是從bash中清空)的空var
#!/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 "[email protected]'.$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;
}
}
?>
嘗試指定'pocketsphinx_continuous'的完整路徑,它可能無法從AGI中找到它? –
@EricRenouf做到了這一點,但它沒有幫助 – user3237558
以AGI身份運行它的用戶是否有權訪問它需要的所有資源?例如,我在'/ root'中看到了對文件的引用,也許你可以從'exec'得到返回值,看看它是否認爲它正在完成而沒有錯誤或者沒有錯誤 –