Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 将音频从麦克风传输到pocketsphinx和浏览器_Apache_Pocketsphinx_Gstreamer 1.0 - Fatal编程技术网

Apache 将音频从麦克风传输到pocketsphinx和浏览器

Apache 将音频从麦克风传输到pocketsphinx和浏览器,apache,pocketsphinx,gstreamer-1.0,Apache,Pocketsphinx,Gstreamer 1.0,我想将音频从我的Raspberry Pi的麦克风一次传输到一个定制的pocketsphinx应用程序和浏览器。我该怎么做?首先我想让它在我的本地网络上工作,但是这种技术也应该可以在广域网上使用 我已经拥有的: 服务器: gst-launch-1.0 alsasrc!音频/x-raw,endianness=1234,signed=true,width=16,depth=16,rate=44100,channels=1,format=S16LE!音频转换!音频重采样!tcpserversink主机=

我想将音频从我的Raspberry Pi的麦克风一次传输到一个定制的pocketsphinx应用程序和浏览器。我该怎么做?首先我想让它在我的本地网络上工作,但是这种技术也应该可以在广域网上使用

我已经拥有的:

服务器:

gst-launch-1.0 alsasrc!音频/x-raw,endianness=1234,signed=true,width=16,depth=16,rate=44100,channels=1,format=S16LE!音频转换!音频重采样!tcpserversink主机=127.0.0.1端口=3000

客户:

gst-launch-1.0 tcpclientsrc主机=127.0.0.1端口=3000!音频/x-raw,endianness=1234,signed=true,width=16,depth=16,rate=44100,channels=1,format=S16LE!音频转换!音频重采样!口袋狮身人面像!fakesink

我将用流媒体服务器的本地ip替换127.0.0.1

这似乎适用于pocketsphinx。但是,我需要如何调整该命令才能流式传输到浏览器?我已经安装了Apache2 html+PHP服务器。当一个客户访问我的网站时,我希望他听到麦克风发出的声音,而计算机上的另一个应用程序同时需要pocketsphinx。

如中所示,您可以使用
tee
插件将gstreamer流拆分为两个,并将它们流到不同的端点:

gst-launch-1.0 alsasrc ! audio/x-raw, endianness=1234, signed=true, width=16, depth=16, rate=44100, channels=1, format=S16LE ! audioconvert ! audioresample ! tee name=t ! tcpserversink host=127.0.0.1 port=3000 t. ! rtpL16pay name=pay0

另请参见。

我终于想出了办法。感谢尼古拉·什米雷夫为我指明了正确的方向。我写了完整的说明如何做到这一点,如果有人想这样做,我会把它们贴在这里

这将描述如何在raspberry pi上设置实时音频流服务器+pocketsphinx语音识别服务。应该也适用于其他Linux发行版

1) 安装软件包

sudo apt-get install gstreamer-1.0 gstreamer1.0-tools apache2 libapache2-mod-php libopus-dev libmicrohttpd-dev libjansson-dev libssl-dev libsrtp-dev libsofia-sip-ua-dev libglib2.0-dev libopus-dev libogg-dev libcurl4-openssl-dev liblua5.3-dev libconfig-dev pkg-config gengetopt libtool automake git bison python-dev swig make gedit firefox-esr
2) 杰纳斯

git clone https://github.com/meetecho/janus-gateway
cd janus-gateway
sh autogen.sh
./configure --prefix=/opt/janus
make -j4
sudo make install
sudo make configs
cd ..
3) 编译cmusphinx

git clone https://github.com/cmusphinx/sphinxbase
git clone https://github.com/cmusphinx/pocketsphinx
git clone https://github.com/cmusphinx/sphinxtrain
cd sphinxbase
./autogen.sh
make -j4
sudo make install
cd ..
cd pocketsphinx
./autogen.sh
make -j4
sudo make install
cd ..
cd sphinxtrain
./autogen.sh
make -j4
sudo make install
cd ..
pip install pocketsphinx
4) 更新janus配置文件

只需将/opt/janus/etc/janus/janus.plugin.streaming.jcfg的内容替换为以下内容:

; You should ensure that one of the streams configured for Janus is the
; following. You need to edit 
;
;       /opt/janus/etc/janus/janus.plugin.streaming.cfg
;
; and add/modify it to have the following section. Make sure all other
; sections in that file are commented out/deleted.

[gstreamer-sample]
type = rtp
id = 1
description = Opus/VP8 live stream coming from gstreamer
audio = yes
audioport = 5002
audiopt = 111
audiortpmap = opus/48000/2
secret = adminpwd
5) 设置环境变量

您需要在使用pocketsphinx的每个终端中运行此命令,您可以将其添加到.bashrc文件中:

export LD_LIBRARY_PATH=/usr/local/lib 
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
6) 将janus gateway/html的内容复制到apache2目录(可能是/var/www/html)

7) 将默认音频设置为usb声卡并重新启动

gedit /usr/share/alsa/alsa.conf
将显示:

defaults.ctl.card 0
defaults.pcm.card 0
将其更改为:

defaults.ctl.card 1 defaults.pcm.card 1 8) 重新启动apache2

sudo service apache2 restart
9) 启动janus

janus -F /opt/janus/etc/janus
10) 运行gstreamer命令1:

gst-launch-1.0 alsasrc ! audio/x-raw, endianness=1234, signed=true, width=16, depth=16, rate=44100, channels=1, format=S16LE ! tee name=t \
    t. ! queue ! audioconvert ! audioresample ! tcpserversink host=127.0.0.1 port=3000 \
    t. ! queue ! audioresample ! audio/x-raw, channels=1, rate=16000 ! opusenc bitrate=20000 ! rtpopuspay ! udpsink host=127.0.0.1 port=5002
您应该在启动janus的终端中看到类似“新音频流”的内容

11) 运行gstreamer命令2:

gst-launch-1.0 tcpclientsrc host=127.0.0.1 port=3000 ! audio/x-raw, endianness=1234, signed=true, width=16, depth=16, rate=44100, channels=1, format=S16LE ! audioconvert ! audioresample ! pocketsphinx ! fakesink
**)完了

您可以转到,单击Plugin Demo:Streaming选项卡上的“开始”,选择“Opus/VP8 live stream from gstreamer(live)”并单击“观看或收听”。你会听到从麦克风传来的声音。通过将127.0.0.1替换为raspberry pi的ip地址,您可以从本地网络中的任何计算机访问此站点。我在chrome上遇到过问题,请使用firefox。我们在1)中安装了它。您可以从菜单或在终端中键入“firefox esr”启动它


您可以查看pocketsphinx/src/gst plugin/livedemo.c或livedemo.py,了解如何将pocketsphinx与gstreamer一起使用。

谢谢。但是,当我这样做并测试它时(我将pocketsphinx!fakesink更改为alsasink进行测试),我从扬声器中听到的声音分辨率非常差。使用旧的服务器命令,我没有这个问题。顺便问一下,如何使用您建议的命令在浏览器中播放声音?
gst-launch-1.0 alsasrc ! audio/x-raw, endianness=1234, signed=true, width=16, depth=16, rate=44100, channels=1, format=S16LE ! tee name=t \
    t. ! queue ! audioconvert ! audioresample ! tcpserversink host=127.0.0.1 port=3000 \
    t. ! queue ! audioresample ! audio/x-raw, channels=1, rate=16000 ! opusenc bitrate=20000 ! rtpopuspay ! udpsink host=127.0.0.1 port=5002
gst-launch-1.0 tcpclientsrc host=127.0.0.1 port=3000 ! audio/x-raw, endianness=1234, signed=true, width=16, depth=16, rate=44100, channels=1, format=S16LE ! audioconvert ! audioresample ! pocketsphinx ! fakesink