PyFLAC - Real-time lossless audio compression in Python

Overview
https://raw.githubusercontent.com/sonos/pyFLAC/develop/assets/logo-white-background.jpg https://readthedocs.org/projects/pyflac/badge https://img.shields.io/pypi/pyversions/pyFLAC

A simple Pythonic interface for libFLAC.

FLAC stands for Free Lossless Audio Codec, an audio format similar to MP3, but lossless, meaning that audio is compressed in FLAC without any loss in quality. This is similar to how Zip works, except with FLAC you will get much better compression because it is designed specifically for audio.

pyFLAC allows you to encode and decode raw audio data directly to/from a file, or in real-time using callbacks.

Installation

You can use pip to download and install the latest release with a single command.

pip3 install pyflac

Note

pyFLAC depends on libsndfile, which requires an extra install step on Linux distributions. See the SoundFile documentation for more information.

Supported platforms

  • macOS
  • Linux
  • RPi Zero/2/3/4
  • Windows 7/8/10

CLI

pyFLAC comes bundled with a command line tool to quickly convert between WAV and FLAC files. For more information, print the help info.

pyflac --help

Note

If you didn't install pyFLAC globally then the command line tool will not be installed on your PATH. However you should still be able to access the tool with python3 -m pyflac.

Comments
  • Illegal Instruction

    Illegal Instruction

    Hello, I am trying to use pyflac on raspberry pi zero, but I am getting Illegal instruction error.

    Collecting pyflac
      Downloading https://files.pythonhosted.org/packages/21/ec/621fd90f1b98477fa1c147edab0ea54cb8bd4b34773f698d5da665a197f3/pyFLAC-2.0.0.tar.gz (1.8MB)
         |████████████████████████████████| 1.8MB 1.0MB/s
    Requirement already satisfied: cffi>=1.4.0 in /home/pi/.local/lib/python3.8/site-packages (from pyflac) (1.15.0)
    Collecting SoundFile>=0.8.0 (from pyflac)
      Downloading https://files.pythonhosted.org/packages/eb/f2/3cbbbf3b96fb9fa91582c438b574cff3f45b29c772f94c400e2c99ef5db9/SoundFile-0.10.3.post1-py2.py3-none-any.whl
    Requirement already satisfied: numpy in /home/pi/.local/lib/python3.8/site-packages (from pyflac) (1.22.4)
    Requirement already satisfied: pycparser in /home/pi/.local/lib/python3.8/site-packages (from cffi>=1.4.0->pyflac) (2.21)
    Building wheels for collected packages: pyflac
      Building wheel for pyflac (setup.py) ... done
      Created wheel for pyflac: filename=pyFLAC-2.0.0-cp38-cp38-linux_armv6l.whl size=1938080 sha256=30e340d066abeca1358fca4f26c1f82151e68ece9a1880f5345360b523eecd3b
      Stored in directory: /home/pi/.cache/pip/wheels/5a/96/19/863b328487fa805e47b53d7da91885d99770ceae1af630e38e
    Successfully built pyflac
    Installing collected packages: SoundFile, pyflac
    Successfully installed SoundFile-0.10.3.post1 pyflac-2.0.0
    
    Python 3.8.1 (default, May 25 2022, 20:18:49)
    [GCC 8.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import soundfile
    >>> import pyflac
    Illegal instruction
    
    bug 
    opened by triggerfinger-debug 5
  • Implement callbacks and streamable subset option

    Implement callbacks and streamable subset option

    Implements seek and tell callbacks so that the stream encoder can insert metadata at the start of the file.

    Implements metadata callback, although currently the callback just receives a blob of cdata.

    Makes streamable subset optional to allow the use of the full format settings.

    enhancement 
    opened by ali1234 5
  • Compress more than 2 channels

    Compress more than 2 channels

    Hi,

    First of all thank you for the package and the examples!

    I'm currently looking for methods to compress data from neural electrophysiology recorded from the brain. We use neural probes with many channels (e.g. 384) and I was wondering if there is a way to tweak the library to allow for more than 2 channels. Is it possible?

    Thank you in advance! Alessio

    opened by alejoe91 3
  • Merge to main: v2.1.0

    Merge to main: v2.1.0

    • Added support for Linux arm64 architectures
    • Added support for Darwin arm64 architectures (macOS Apple Silicon)
    • Fixed Raspberry Pi Zero library (see #13)
    • Updated FLAC library to v1.3.4
    opened by joetoddsonos 1
  • Bugfix/readme logo

    Bugfix/readme logo

    Changed logo url in README.rst to https://raw.githubusercontent.com/sonos/pyFLAC/develop/assets/logo-black.png Tested on MacOS Chrome, and MacOS + iOS Safari

    opened by conorsleithsonos 1
  • v1.0.0 review

    v1.0.0 review

    I think this is in a good enough state now to review.

    Would like to hear your opinions on the API, at the moment it's pretty much just copied exactly from the libFLAC design. You can see some examples of usage in

    • examples/passthrough.py: illustrates both encoder/decoder callbacks by passing data from a WAV file through them both. It also verifies that the uncompressed output is exactly the same as the original WAV audio data.
    • examples/stream.py: streams audio data from the microphone and passes it through the encoder, optionally saving the output to a FLAC file.
    • pyflac/__main__.py: this is the main module for the package (which is also used for the CLI tools, as it makes things more accessible on Windows and if you don't install globally). It converts WAV -> FLAC files and vice versa.

    Note: if you are changing things and want to develop locally, read CONTRIBUTING.rst. You have to explicitly build the CFFI .so (this is done automatically when using setuptools to install).

    good first issue help wanted 
    opened by joetoddsonos 1
  • Merge to main - v2.0.0

    Merge to main - v2.0.0

    External contribution from @ali1234. Retested against previous benchmarks and it does not affect performance.

    • Added seek and tell callbacks to StreamEncoder
    • Renamed the write callbacks from callback to write_callback for StreamEncoder and StreamDecoder
    enhancement 
    opened by joetoddsonos 0
  • Tests don't properly check the raised exception

    Tests don't properly check the raised exception

    https://github.com/sonos/pyFLAC/blob/19b3322851ac6e9e8abe2ddd4f285c90a52c7f97/tests/test_encoder.py#L127-L129

    The third line here has no effect. If encoder._init() raises an exception (which we expect it to), all subsequent lines won't run at all.

    opened by ali1234 0
  • Fix stuttering if sleeping in between processing

    Fix stuttering if sleeping in between processing

    The robot effect was due to the fact that the audio data passed to the sounddevice/portaudio callback, sometimes occupied the same memory region in consecutive callbacks. Which meant that by the time we processed it (after sleeping a little while), the audio blocks had been overwritten, leading to the stuttering kind of robot effect.

    So I have reverted to a raw audio stream. Converting to bytes before adding to the queue guarantees that it has its own memory space so it won't get overwritten. Then we convert to a numpy array in the processing thread.

    I chose this over doing a np.copy just because it's takes up less time in the high priority audio callback, which is not so much of an issue here. If you think it is more clear to do an np.copy here I will switch back 👍

    bug 
    opened by joetoddsonos 0
  • Decoder internal queue

    Decoder internal queue

    • Ditch the decoder read_callback by buffering bytes passed in via the process method, and passing to the decoder's read callback internally. Making the encoder and decoder interfaces more alike.
    • Rename write_callback to callback
    enhancement 
    opened by joetoddsonos 0
Releases(v2.1.0)
  • v2.1.0(Oct 26, 2022)

    • Added support for Linux arm64 architectures
    • Added support for Darwin arm64 architectures (macOS Apple Silicon)
    • Fixed Raspberry Pi Zero library (see #13)
    • Updated FLAC library to v1.3.4
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Jul 21, 2021)

  • v1.0.0(Apr 22, 2021)

    • Added a StreamEncoder to compress raw audio data on-the-fly into a FLAC byte stream
    • Added a StreamDecoder to decompress a FLAC byte stream back to raw audio data
    • Added a FileEncoder to convert a WAV file to FLAC encoded data, optionally saving to a FLAC file
    • Added a FileDecoder to convert a FLAC file to raw audio data, optionally saving to a WAV file
    • Bundled with libFLAC version 1.3.3
    Source code(tar.gz)
    Source code(zip)
    ocean-1.0.0.tar.gz(56.07 KB)
Owner
Sonos, Inc.
The Wireless Hi-Fi system
Sonos, Inc.
C library for cross-platform real-time audio input and output

libsoundio C library providing cross-platform audio input and output. The API is suitable for real-time software such as digital audio workstations as

Andrew Kelley 1.6k Jan 6, 2023
PortAudio is a portable audio I/O library designed for cross-platform support of audio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.

PortAudio 786 Jan 1, 2023
C++ library for audio and music analysis, description and synthesis, including Python bindings

Essentia Essentia is an open-source C++ library for audio analysis and audio-based music information retrieval released under the Affero GPL license.

Music Technology Group - Universitat Pompeu Fabra 2.3k Jan 7, 2023
C++ audio time-stretching implementation

Time Stretcher C++ audio time-stretching implementation, based on the algorithms presented in: Audio Time Stretching with an Adaptive Phase Vocoder, N

null 59 Nov 13, 2022
A simple C++ library for reading and writing audio files.

AudioFile A simple header-only C++ library for reading and writing audio files. Current supported formats: WAV AIFF Author AudioFile is written and ma

Adam Stark 683 Jan 4, 2023
A C library for reading and writing sound files containing sampled audio data.

libsndfile libsndfile is a C library for reading and writing files containing sampled audio data. Authors The libsndfile project was originally develo

null 1.1k Jan 2, 2023
C++ Audio and Music DSP Library

_____ _____ ___ __ _ _____ __ __ __ ____ ____ / \\_ \\ \/ / |/ \| | | | \_ \/ \ | Y Y \/ /_ \> <| | Y Y \ | |_|

Mick Grierson 1.4k Jan 7, 2023
Single file audio playback and capture library written in C.

A single file library for audio playback and capture. Example - Documentation - Supported Platforms - Backends - Major Features - Building - Unofficia

David Reid 2.6k Jan 8, 2023
Easy and efficient audio synthesis in C++

Tonic Fast and easy audio synthesis in C++. Prefer coding to patching? Love clean syntax? Care about performance? That's how we feel too, and why we m

null 482 Dec 26, 2022
An audio mixer that supports various file formats for Simple Directmedia Layer.

An audio mixer that supports various file formats for Simple Directmedia Layer.

Simple Directmedia Layer 198 Dec 26, 2022
Explore fractals in an audio-visual sandbox

Fractal Sound Explorer Explore fractals in an audio-visual sandbox Download executable on my itch.io page: https://codeparade.itch.io/fractal-sound-ex

null 983 Jan 4, 2023
Audio out with an FTDI UART cable

Audio out with an FTDI UART cable This encodes audio as either PDM (using a first order sigma-delta stage), 32-bits PWM or 64-bits PWM and sends it as

Konrad Beckmann 42 Jun 23, 2022
Sexy, audio-responsive effects on LED strips.

Striptease Sexy, audio-responsive effects on LED strips. For Teensy 4 with Audio Adapter Board, by PJRC. Quick demo Shooting video of LEDs is very tri

Luca Paolini 35 Jun 19, 2022
audio monitor filter for OBS Studio

Audio Monitor dock and filter for OBS Studio Plugin for OBS Studio to add Audio Monitor dock and filter. It allows you to put the audio of a OBS sourc

Exeldro 222 Dec 18, 2022
Lightweight Embedded Audio Framework

LEAF (Lightweight Embedded Audio Framework) is a C library for audio synthesis and processing created by Jeff Snyder, Mike Mulshine, and Matt Wang at Princeton University's New Instrument Research Lab. It was originally called OOPS when we started writing it in 2017, so you may see references to it under that name as well.

Jeff Snyder 110 Dec 27, 2022
An Audio Steganography Tool, written in C++

HiddenWave Hide your personal Data inside The Audio wav file Written in C++ by Gaurav Raj [TheHackersBrain] Hiddenwave is an audio steganography tool

Gaurav Raj 48 Dec 27, 2022
Block all ads in vídeo, áudio, banner, anti-skip

NoAdSpotify Block spotify ad This is an updated and simplified version of the project: BlockTheSpot Last updated: 6th June 2021 Last tested version: 1

null 14 Nov 5, 2022
Arduino Audio Tools (Music Player, Music Recorder supporting I2S, Microphones, DAC, ADC, A2DP, Url)

Arduino Audio Tools Some basic header-only C++ classes that can be used for Audio Processing provided as Arduino Library: a simple I2S class (to read

Phil Schatzmann 527 Jan 7, 2023