SBC is a digital audio format used for transferring audio between Bluetooth host and output devices like headphones or loudspeakers. This article explains how to convert audio files to and from SBC codec format in Linux.

What is SBC

Bluetooth Spec defines SBC (Low Complexity Subband Coding) an audio subband codec specified for the Audio transmission between Bluetooth devices and Host.

SBC is a digital audio encoder and decoder used to transfer data to Bluetooth audio output devices like headphones or loudspeakers.

In Linux here is the command to encode/decode a audio and send it to Bluetooth headset. For conversion a commandline tool named sox (SoX - Sound eXchange, the Swiss Army knife of audio manipulation) will be used. mpg123 will be used for mp3/wav conversion.

How to convert mp3 to SBC format

mpg123 -q -s test.mp3 | sox -t raw -r 44100 -c 2 -s -w - -t raw -r 8000 -c 1 -s -w out.sbc

We can also directly play the mp3 file to headset by piping the output to bluez hstest test application

mpg123 -q -s test.mp3 | sox -t raw -r 44100 -c 2 -s -w - -t raw -r 8000 -c 1 -s -w - | ./hstest play - $BDADDR $CHANNEL

How to convert SBC format file to wav

sox -t raw -r 8000 -c 1 -s -w inputfile.sbc -b 16 -r 44100 -c 2 -s outfile.wav

Similary we can save bluetooth audio (mic) input to wave file by piping bluez hstest test application output to sox

./hstest record - $BDADDR $CHANNEL | sox -t raw -r 8000 -c 1 -s -w - -b 16 -r 44100 -c 2 -s outfile.wav