Connecting Hearing Aids to Linux via Bluetooth
"Debugging becomes significantly easier if you first admit that you are the problem," ~ William Laeder
I recently wanted to connect my hearing aids to my laptop to watch a movie. Based on everything I could find online and from the Hearing Aid manufacturer directly, I had to purchase a second device that would act as an intermediary to the laptop, TV, etc. That seemed odd, as I’d always used them directly with my mobile phone, with an app from the manufacturer.
After some digging, my first discovery was that, aside from the sheer complexity of the Bluetooth protocol, there were two separately developed protocols for devices like hearing aids. Why, I'm not sure, ~~probably~~ certainly money is involved. The older is ASHA, which was co-developed by the companies Google and Cochlear. The "newer" LE Bluetooth protocol is over 10 years old and has many advantages over ASHA. However, hearing aid manufacturers have only just recently started to roll out this on their hardware. Making things more complicated is figuring out if your computer's Bluetooth hardware supports whatever is running on the chip in your ear.
In my case, my hearing aids are still using ASHA, which wasn't supported by my computer without some 3rd party assistance. That is how I came to fall down the Bluetooth rabbit hole to try and figure out how to get these two strangers to talk to each other.
Spoiler Alert: I’m not an expert on Bluetooth by any stretch of the imagination. I’m just a person who wanted to listen to music and hacked around until it worked. What I will try to do is to distill some of the mystery surrounding it.
I’ll briefly cover how Bluetooth works and how I worked on connecting my hearing aids to the laptop. If you don't care about the what or why behind Bluetooth and just want to connect, you can skip ahead to the instructions.
Bluetooth setup (specifically on Linux)
At the end of the day, if you take nothing else away, just remember that Bluetooth is very similar to network programming in its setup. There are no DNS servers involved here though, which is where the differences start to show. From a Linux user’s standpoint, they turn on their Bluetooth-capable device(like earbuds), search for it (from a GUI or CLI manager), “connect” or “pair” with it, and then output sound to it.
The pieces involved under the hood look something like this:
User Applications
- Connects To: Sound Servers
- Interaction: Applications send audio streams to sound servers
- Examples: Media players (e.g., VLC), VoIP apps (e.g., Zoom), system settings
- Protocols Used: PulseAudio API, PipeWire API, JACK API
Sound Servers
- Connects To: ALSA (Kernel-Level Sound System) & Bluez (BLuetooth stack)
- Interaction: Sound servers mix and route audio before sending it to ALSA or BlueZ
- Examples: PulseAudio, PipeWire, JACK
- Protocols Used: ALSA API, JACK audio connection kit
ALSA(Advanced Linux Sound Architecture)[1]
- Connects To: Hardware Drivers
- Interaction: ALSA sends audio data to hardware drivers (internal speakers, microphones, sound cards)
- Protocols Used: Kernel system calls, device-specific drivers
Bluetooth Deamon (BlueZ)
- Connects To: Bluetooth device drivers
- Interaction: Manages Bluetooth devices and sends audio streams
- Protocols Used: A2DP (Advanced Audio Distribution Profile), HSP/HFP (Headset Profile), HCI (Host Controller Interface)
Bluetooth Device Drivers
- Connects To: Headphones/Speakers/Microphone hardware
- Interaction: Sends processed audio from BlueZ to Bluetooth devices
- Protocols Used: Same as with BlueZ daemon. Bluetooth HCI, A2DP, HSP
D-Bus Communication
D-Bus is an Interprocess Communication Layer that is used for communication between various system components. It's like the glue holding all these disparate pieces together. A super skilled translator at the United Nations allowing all the delegates to converse. A Babel Fish[2], if you will. 😉
Connecting Hearing Aids to a Linux Laptop
I found a GitHub repo that had a C-based ASHA Sink <--> Pipewire utility and used that to connect. The steps and flow are as follows:
Requirements / Installation
You will need a copy of the ASHA-Pipewire Sink repo:
`git clone https://github.com/thewierdnut/asha_pipewire_sink.git`
Ensure you have all of the required packages to build the executable(for Fedora):
`sudo dnf install cmake pipewire pipewire-alsa pipewire-devel bluez-libs-devel bluez-libs`
- A/N #1:* If you have Debian, refer to the repo's README prerequisites[3].
- A/N #2:* If you have neither, you'll need to examine each package and try to find the equivalent for your OS (if it exists). Good luck!
# Enable LE credit based flow control
1. `sudo touch /etc/modprobe.d/bluetooth_asha.conf`
2. Add following line to "/etc/modprobe.d/bluetooth_asha.conf": `options bluetooth enable_ecred=1`
# Change the default connection interval
Update (ie. sudoedit) `/etc/bluetooth/main.conf` to contain the following settings:
[LE] # LE default connection parameters. These values are superceeded by any # specific values provided via the Load Connection Parameters interface MinConnectionInterval=16 MaxConnectionInterval=16 ConnectionLatency=10 ConnectionSupervisionTimeout=100
# Restart Bluetooth service for changes to take effect
sudo systemctl restart bluetooth
# Build the ASHA-Pipewire Sink executable & move it into your PATH
1. `mkdir build`
2. `cd build`
3. `cmake ..`
4. `make`
5. `cp ./asha_pipewire_sink $HOME/.local/bin/`
# Connecting everything up:
1. Run the ASHA Pipewire Sink - `asha_pipewire_sink &`
2. Connect to the HA via Bluetooth - `bluetoothctl connect 00:42:8E:42:EC:42`
3. Ensure that your HA is set as the target output device
4. Play audio and enjoy!
✨ 🎶 Hapy streaming! 🎶 ✨
---
- *ASIDE:** The BlueZ project has just recently merged updates to their codebase[4] to allow them to support ASHA! There's still other pieces to fall into place, but progress is slowly being made. 💖
---
© 2024-present by Andie Keller.
Content of this website is licensed under CC BY-NC-SA 4.0.
Crafted with 💖. Built with gempost.