Close

Python : audio capture & playback

A project log for digital-walkie-talkie

long range, low power, modular

christoph-tackChristoph Tack 08/10/2020 at 11:320 Comments

Requirements for pyaudio:

sudo apt install libportaudio2 libportaudiocpp0 python3-pip portaudio19-dev
sudo pip3 install pyaudio
sudo pip3 install sounddevice

Some simple test applications:

References:

Audio resampling

Codec2 works with a fixed sample rate of 8kHz.  The line-in and line-out work at 48kHz.  A sample rate conversion is needed.  Several options are considered:

audioop.ratecv

No libraries need to be installed.  The implemented filters are simple first order filters and it certainly sounds like that.

This works both on the Core i7 8thGen and the Wandboard.

play_sound_ratecv

samplerate

sudo pip3 install samplerate

This library runs fine on a Core i7 8thGen and on the Wandboard.  Be sure to convert the output of this library to int16 before feeding it back to pyAudio.  Python doesn't complain about wrong types as a C++ program would, but the result sounds terrible.

This "sync-best"-filter is audibly the best performing filter.

play_sound_samplerate

resampy

Works fine on a Core i7 8thGen.  Takes more than two hours to build on a Wandboard.  This package has more than 300MB of dependencies.

sudo apt install gfortran llvm-dev libblas3 liblapack3 liblapack-dev libblas-dev
sudo pip3 install resampy

play_sound_resampy : open a 8kHz wave file, up-sample it to 48kHz and then play it.  Works fine on a Core i7 8thGen.  On the Wandboard, it takes much longer to start and it hangs.  No sound is ever generated.

Discussions