Sonos Releases pyFLAC Library for Realtime Lossless Audio Compression in Python

May 31 2021, 00:55
FLAC is the most universal compression algorithm for audio, allowing to maintain a perfect reconstruction of the original data. As an audio manufacturer that supports FLAC in all its home audio (Wi-Fi) products, Sonos decided to improve its own development tools by creating an efficient alternative to using the original FLAC library (libFLAC) written in C, and created a Python implementation for lossless encoding/decoding focusing on real-time streams. pyFLAC is now available as a free-to-use package.
 

Sonos continues to invest strongly in new talent to expand its R&D team, but the multiroom audio pioneer also gained significant reach in the world of audio software and open source solutions with the acquisition in 2020 of the talented team of Chirp.io - the data-over-sound pioneer. A member of the original Chirp team is Joe Todd, now Senior Software Engineer, Advanced Technology at Sonos, which recently revealed all the details about the new pyFLAC library in the company's website.

"Here in the Advanced Technology research department of Sonos, we are investigating ways in which audio can be used to infer and compensate for particular characteristics of our environment. One example of this is Trueplay, in which audio is used to capture the response of a particular room, which can subsequently be used to tune the speakers for optimized sound quality. 

"When researching and developing new features like Trueplay, we have to undergo large data collection efforts to gather an accurate picture of the many different locations one might find a Sonos speaker. In the initial stages of development, we often begin this process on prototype hardware such as Raspberry Pi, in order to prove that an idea can be realized in practice. We may also need to train and verify machine learning models on the collected data before making further commitments to development."

When collecting raw audio data, the throughput can get reasonably large as more microphones are introduced, so any reductions we can make without removing information from the signal are worthwhile. For example, if we are transmitting 16-bit audio data from 3 devices, each with 4 microphones at 44.1kHz, then the throughput is just above 8Mbps. Since a perfect reconstruction of the original data is required, FLAC is the obvious candidate to reduce the bandwidth, and can do so by around 50% in many contexts
," Joe Todd writes.

FLAC stands for Free Lossless Audio Codec and is maintained by Xiph.org, it is free and open-source, and remains the most widely supported lossless audio codec. "The FLAC library itself (libFLAC) is written in C, which is great for performance and efficiency, but not so great for fast-paced research and development. We often select Python as our language of choice for internal R&D projects, as it means less time writing code, and more time focussing on the research itself.

"There are many different existing Python implementations for FLAC encoding/decoding. However, these tend to operate on files, rather than real-time streams, which is no good for continuous processing. Of course, we should never reinvent the wheel; instead, we can use CFFI to expose the functionality of libFLAC in Python. So, welcome to pyFLAC: a Python library for realtime lossless audio compression using libFLAC. In the spirit of open-source, we are releasing pyFLAC as a free-to-use package which can be installed directly from PyPi using pip,
" Todd adds.

"Ultimately the pyFLAC package has allowed us to transmit high quality audio data more efficiently in our internal research projects, reducing data rates by around 40%. The ability to apply this to raw audio streams in real-time means it can support large data collections without the need of additional post processing from disk. We hope that by releasing the package on PyPi, others may also benefit from lossless audio compression in their Python projects. If you would like to try out pyFLAC yourself you can find more comprehensive examples in the documentation at readthedocs.org. Furthermore, if you wish to contribute to the pyFLAC project or just view the source code, then head over to github.com/sonos/pyFLAC."

Read the complete internal article available here.
www.sonos.com
Page description
About Joao Martins
Since 2013, Joao Martins leads audioXpress as editor-in-chief of the US-based magazine and website, the leading audio electronics, audio product development and design publication, working also as international editor for Voice Coil, the leading periodical for... Read more

related items