Pi Record is an application to record audio files from microphones. I am developing it primarily to record from a Blue Yeti USB microphone and from a Focusrite Scarlett 2i2 pre amp and USB interface for more ordinary microphones. I have small Raspberry Pi 4 2GB model which I want to take with me to where I am recording. It has wifi enabled and is designed to sit close to my piano.
I want to control this recorder with my iPad. The obvious way to do this is for the Raspberry Pi to run a web server and serve a Web Application which can send messages to the server to control it. This is what this post is about.
Requirements for The Recorder
The requirements for this application can be split into two parts, the server and the client (provided to a browser by the server).
- Support multiple potemtial clients to be operating simultenously. This required the user on that device to take control of an interface before they could control it.
- Provide running loudness data and present it to the user as something like a a Vue Meter and a loudness trace
- Realise that on the iPad specfically, putting the browser into the background could make it go to sleep.
The core of the application is the use of
ffmpeg to handle reading the audio
data and converting it to a
.flac audio file which may later be recovered
sftp) to a desktop for post production intergration with the video
ffmpeg can also produce an loudness stream.
I found the following command
ffmpeg -hide_banner -f alsa -ac 2 -ar 48k -i hw:CARD=USB -filter_complex \ "asplit=2[main][vol],[vol]showvolume=rate=25:f=0.95:o=v:m=p:dm=3:h=80:w=480:ds=log:s=2[vid]" \ -map [main] -c:a:0 flac recordings/session_$(date +%a_%d_%b_%Y___%H_%M_%S).flac \ -map [vid] -preset veryfast -g 25 -an -sc_threshold 0 -c:v:1 libx264 \ -b:v:1 2000k -maxrate:v:1 2200k -bufsize:v:1 3000k -f hls -hls_time 4 \ -hls_flags delete_segments+temp_file -strftime 1 \ -hls_segment_filename volume/volume-%Y%m%d-%s.ts volume/volume.m3u8 2>/dev/null
as an example of how record the
.flac file but also how to produce a video
stream of the volume. The first prototype streamed the video to the client,
but failed because the video stream was well out of sync with the actual
But then I discovered the Loudness Standard r128 and the filter
ffmpeg had for producing a stream of values about every 10th Second. So the software was revised and so the current command is used, feeding into
sed to take the textual loudness data and compress it to its essential values to stream to the client:-
ffmpeg -hide_banner -nostats -f alsa -acodec pcm_s32le -ac:0 2 -ar 192000 -i hw:dddd -filter_complex asplit=2[main][vols],[vols]ebur128=peak=true:meter=18[vol] -map [main] | sed -u -n s/.*TARGET:-23 LUFS\\(.*\\)LUFS.*FTPK:\\([^d]*\\)*.*TPK:\\([^d]*\\).*$/\\1 P: \\2 K: \\3/p
Server Send Events are used to provide two streams of events to the user. Status change events (Microphones being plugged in our out, clients taking control of or releasing the interface) and Volume Streams.
The UI is pretty too.