立即将音频从麦克风传输到 pocketsphinx 和浏览器
Stream audio from microphone to pocketsphinx and browser at once
我想将音频从我的 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。
就像在 中一样,您可以使用 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
我终于知道怎么做了。感谢 Nikolay Shmyrev 为我指明了正确的方向。我写了完整的操作说明,如果有人想这样做,我 post 在这里。
这将描述如何在 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) 编译 janus
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)
sudo cp -a janus-gateway/html/. /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
重启:
sudo reboot
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 的终端中看到类似 "New Audio Stream!" 的内容。
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
**) 完成!
您可以转到 http://127.0.0.1/streamingtest.html,在插件演示:流媒体选项卡上单击 "Start",select "Opus/VP8 live stream coming from gstreamer (live)",然后单击 "Watch or Listen"。您会听到麦克风发出的声音。您可以通过将 127.0.0.1 替换为 raspberry pi 的 IP 地址,从本地网络中的任何计算机访问该站点。我在使用 chrome 时遇到过问题,请使用 firefox。我们在 1) 中安装了它。您可以从菜单或在终端中输入 "firefox-esr" 来启动它。
您可以查看 pocketsphinx/src/gst-plugin/livedemo.c 或 livedemo.py 以了解如何将 pocketsphinx 与 gstreamer 一起使用。
我想将音频从我的 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。
就像在 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
我终于知道怎么做了。感谢 Nikolay Shmyrev 为我指明了正确的方向。我写了完整的操作说明,如果有人想这样做,我 post 在这里。
这将描述如何在 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) 编译 janus
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)
sudo cp -a janus-gateway/html/. /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
重启:
sudo reboot
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 的终端中看到类似 "New Audio Stream!" 的内容。
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
**) 完成!
您可以转到 http://127.0.0.1/streamingtest.html,在插件演示:流媒体选项卡上单击 "Start",select "Opus/VP8 live stream coming from gstreamer (live)",然后单击 "Watch or Listen"。您会听到麦克风发出的声音。您可以通过将 127.0.0.1 替换为 raspberry pi 的 IP 地址,从本地网络中的任何计算机访问该站点。我在使用 chrome 时遇到过问题,请使用 firefox。我们在 1) 中安装了它。您可以从菜单或在终端中输入 "firefox-esr" 来启动它。
您可以查看 pocketsphinx/src/gst-plugin/livedemo.c 或 livedemo.py 以了解如何将 pocketsphinx 与 gstreamer 一起使用。