I want to stream audio from my Raspberry Pi’s microphone to a custom pocketsphinx application and a browser at one time. How would I do this? I want to get it working on my local network at first, but the technique should be usable over WAN as well.
What I already have:
server:
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
client:
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
I would replace 127.0.0.1 with my streaming server’s local ip.
This seems to work fine with pocketsphinx. But how do I need to adapt the command in order to stream to a browser as well? I have Apache2 html + PHP server installed. When a client visits my website, I want him to hear the sound from the mic, while another application on the computer needs pocketsphinx at the same time.
2
Answers
I finally figured out how to do it. Thanks to Nikolay Shmyrev for pointing me in the right direction. I wrote complete instructions how to do it and I post them here if anyone wants to do the same.
This will describe how to setup a live audio streaming server + pocketsphinx speech recognition service on raspberry pi. Should work on other Linux distros as well.
1) Install packages
2) Compile janus
3) Compile cmusphinx
4) Update janus configuration file
Just replace the content of /opt/janus/etc/janus/janus.plugin.streaming.jcfg with the following:
5) Set environment vars
You need to run this in every terminal where you use pocketsphinx, instead you could add this to your .bashrc file:
6) Copy the content of janus-gateway/html to your apache2 directory (probably /var/www/html)
7) Set default audio to usb sound card and reboot
will show:
change it to:
reboot:
8) restart apache2
9) start janus
10) Run gstreamer command 1:
You should see something like "New Audio Stream!" in the terminal where you started janus.
11) Run gstreamer command 2:
**) Finished!
You can go to http://127.0.0.1/streamingtest.html, click "Start" on Plugin Demo: Streaming tab, select "Opus/VP8 live stream coming from gstreamer (live)" and click "Watch or Listen". You will hear the soud coming from your microphone. You can visit this site from any computer in the local network by replacing 127.0.0.1 with the raspberry pi's ip address. I have experienced problems with chrome, use firefox. We installed it in 1). You can start it from the menu or by typing "firefox-esr" in a terminal.
You can check pocketsphinx/src/gst-plugin/livedemo.c or livedemo.py to see how to use pocketsphinx with gstreamer.
Like in Implement multi-stream in Gstreamer you can split gstreamer streams on two with
tee
plugin and stream them to separate endpoints:See also Gsteamer Tee plugin documentation.