Translation tool
For our church we wanted to have a easy, cheap translation system for our english guests (but language doesn't matter :) ). The target was that people can use their phone with the least overhead possible. They just get earplugs if needed and connect to a wifi net to hear the translation.
Alternatives were Beonair which is a app for this problem and http://briggs-inc.com/blog/towf-doc/ which needs an extra laptop.
I chose to use an OpenWRT system on a Netgear WNDR3700v2 Router, which has a USB-Audio Adapter plugged in with Mic input. As I couldn't find any instructions how to setup such a system and it took me a while, here they are:
Software: OpenWRT
At early 2018 mobiles are restricted about streaming and audio without extra app requirements if you're not focussing one either apple or andriod. The highest commmon standard is a HTML5 audio-tag which speaks WAV or MP3 Format. WAV is very bandwidth intensive, but MP3 encoding is quite cpu-intensive.
I couldn't find any broadcast method for both mobile operating systems, so I resigned WAV transmission. For MP3 the usual lame-encoder could not work in real time on my router, so I use the libshine compression.
I started with the latest snapshot of OpenWRT as here ffmpeg was build with libshine bindings. Choose a released version if there is any after 2017.
Then add following software packages (as in wiki.openwrt.org/doc/howto/usb.audio
- kmod-usb-audio
- kmod-sound-core
- alsa
- alsa-utils
And the important and very versatile ffmpeg tool
- ffmpeg
- ffserver
Config
ffserver
The ffserver tool will do most of the work: It starts a ffmpeg in the background which reads the microphone, sends the data to the shine-encoder and forwards the mp3 stream to the ffserver. Then ffserver will act as a webserver listening for browsers who want to download the mp3-file. All this is done in the following ffserver.conf file (to be copied to /etc/)HTTPPort 8090 HTTPBindAddress 0.0.0.0 MaxHTTPConnections 2000 MaxClients 1000 MaxBandwidth 10000 CustomLog -Launch ffmpeg -f alsa -acodec pcm_s16le -ac 1 -i hw:0,0 -ac 1 -acodec libshine -b:a 32k ACL allow 127.0.0.1 Feed feed1.ffm AudioBitRate 32 AudioChannels 1 AudioSampleRate 44100 Preroll 1 NoVideo Format status ACL allow localhost ACL allow 192.168.0.0 192.168.255.255 URL 192.168.1.1/index.html
Some explaining words: With "arecord -l" you can check your audio-hardware. For a router the external usb-audio should be the only one so hw:0,0 should be the first mic. With "arecord -v" you can check the available "codecs" of your hardware. For me stereo little endian with 16bits was the only option. Further parameters will set it to mono and adjust the shineencoder to 32kbit. Then the feed is output to the ffserver with the http protocoll.
Startup
To autostart the streaming after powerup add the file "stream" to /etc/init.d/
#!/bin/sh /etc/rc.common START=55 STOP=15 start() { echo start ffserver -hide_banner } stop() { echo stop killall ffserver }
And start the "stream" service either in the luci or with "/etc/init.d/stream enable". Now you should be able to connect with any browser connected to your router to "http://192.168.1.1:8090/test.mp3" and hear the audio from the mic input. You might have to adjust the volume with alsamixer.
The following configurations are just for convenience (mobile users don't like to type the upper URL)
DNS
You can make a sortofworking automatic redirection by adding:
"address=/#/192.168.1.1" to the end of /etc/dnsmasq.conf (will redirect dns requests)
This file to /etc/firewall.user (will redirect all http)
This file to /etc/config/uhttpd (will redirect all 404 pages to the index.html)
Copying this file to /etc/hosts will give your router the name "translate.lan"
All of this is not working with the newer https. Basically uhttp could server https, but I was too lazy to work out the certificate stuff and I don't want to use a certificate with a deadline as the thing should be easy.
Luckily some browsers detect the nonworking internet and forward you to a http page automatically
Webserver
Basically we just have to knock out the cache system during playback so people will always get the "latest" translation. Caching can be adjusted very well for html pages but for the content inside the best method is to always get the .mp3 with some GET addition. I added also some Javascript for nicer behaviour
This file is my startpage stored in /www/index.html
Problems
Field tests are yet to come, but already it is visible that there is a nonzero lag as the mobiles tend to buffer the mp3 a little bit. Restarting the stream and changing browsers sometimes help. Also the hardware is not really build for streming and encoding so I wonder how many connected users at the same time are possible...