一次将音频从麦克风流传输到Pocketsphinx和浏览器

时间:2019-02-08 17:49:07

标签: apache pocketsphinx gstreamer-1.0

我想一次将Raspberry Pi的麦克风中的音频流传输到自定义的Pocketsphinx应用程序和浏览器。我该怎么做?我想首先让它在我的本地网络上工作,但是该技术也应该可以在WAN上使用。

我已经拥有的东西:

服务器:

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

客户端:

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

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

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

2 个答案:

答案 0 :(得分:1)

我终于弄清楚了怎么做。感谢Nikolay Shmyrev为我指出正确的方向。我写了完整的操作说明,如果有人要这样做,我会在这里张贴。

这将描述如何在树莓派上设置实时音频流服务器+ Pocketsphinx语音识别服务。应该也可以在其他Linux发行版上使用。

1)安装软件包

Parent

2)编译janus

__getattribute__

3)编译cmusphinx

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

4)更新janus配置文件

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

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 ..

5)设置环境变量

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

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

6)将janus-gateway / html的内容复制到您的apache2目录(可能是/ var / www / html)

; 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

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

export LD_LIBRARY_PATH=/usr/local/lib 
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

将显示:

sudo cp -a janus-gateway/html/. /var/www/html

将其更改为:

defaults.ctl.card 1
defaults.pcm.card 1

重启:

gedit /usr/share/alsa/alsa.conf

8)重新启动apache2

defaults.ctl.card 0
defaults.pcm.card 0

9)启动janus

sudo reboot

10)运行gstreamer命令1:

sudo service apache2 restart

您应该看到类似“新音频流!”的内容。在您启动janus的终端中。

11)运行gstreamer命令2:

janus -F /opt/janus/etc/janus

**)完成!

您可以转到http://127.0.0.1/streamingtest.html,在“插件演示:流”选项卡上单击“开始”,选择“来自gstreamer(实时)的Opus / VP8实时流”,然后单击“观看或收听”。您会听到来自麦克风的肥皂水。您可以通过用raspberry pi的IP地址替换127.0.0.1,从本地网络中的任何计算机访问此站点。我在使用Chrome时遇到了问题,请使用Firefox。我们在1)中安装了它。您可以从菜单中启动它,也可以在终端中键入“ firefox-esr”。

您可以检查pocketsphinx / src / gst-plugin / livedemo.c或livedemo.py,以了解如何在gstreamer中使用pocketsphinx。

答案 1 :(得分:0)

就像Implement multi-stream in Gstreamer一样,您可以使用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

另请参阅Gsteamer Tee plugin documentation

相关问题