问题描述
我一直在研究语音识别以及将其实施到网站中的方法.我找到了很多关于将它与 Python 一起使用的示例,甚至还有一个与 Node.js 一起使用的示例,但我希望能够将 PHP 与此一起使用.
I have been looking into Speech Recognition and ways in which this can be implemented into a website. I have found many examples on using it with Python and even one with Node.js but I want to be able to use PHP with this.
有什么方法可以使用 PHP 访问 Linux 服务器上的 CMUSphinx 来处理我的输入?
Is there any way I can access CMUSphinx on a Linux server using PHP to process my inputs?
谢谢
推荐答案
可以做到,但使用星号作为音频捕获和处理引擎.请参阅 http://www.voip-info.org/wiki/view/Sphinx
Can be done but to use asterisks as the audio capture and processing engine. See http://www.voip-info.org/wiki/view/Sphinx
配置服务器后的示例代码
Example code below after your server has been configured
function sphinx($filename='', $timeout=3000, $service_port = 1069, $address = '127.0.0.1'){
/* if a recording has not been passed in we create one */
if ($filename=="") {
$filename = "/var/lib/asterisk/sounds/sphinx_".$this->request['agi_uniqueid'];
$extension = "wav";
$this->stream_file('beep', 3000, 5);
$this->record_file($filename, $extension, '0',$timeout);
$filename=$filename.'.'.$extension;
}
/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
return false;
}
$result = socket_connect($socket, $address, $service_port);
if ($result < 0) {
return false;
}
//open the file and read in data
$handle = fopen($filename, "rb");
$data = fread($handle, filesize($filename));
socket_write($socket, filesize($filename)."\n");
socket_write($socket, $data);
$response = socket_read($socket, 2048);
socket_close($socket);
unlink($filename);
return $response;
}
查看网站后的另一个想法是,sphinx 4 允许 Web 服务访问识别处理守护程序,即:将 sphinx 作为守护程序运行(它的 java!)然后您可以像上面那样打开套接字以将 .wav 输入其中直接基本上使用对上面代码的修改,因此不是调用星号服务器来检索然后录制音频,而是使用其他东西,例如 html5 等来录制音频.
Another thought after looking at the website is that sphinx 4 allows web service access to the recognition processing daemon ie: run sphinx as a daemon (its java!) then you can do socket opens as above to feed a .wav into it directly basically using a modification of the code above so instead of calling the asterisks server to retrieve then record the audio you would use something else perhaps html5 etc to record the audio.
另一件需要考虑的事情是 chrome 和 html5 内置了语音识别
Another thing to consider is that chrome and html5 has built in speech recognition
这篇关于使用 PHP 连接到 CMU Sphinx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!