Skip to content

Commit ba45eec

Browse files
committed
docs: add linux hearing aid script
1 parent 6902ba1 commit ba45eec

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

linux/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,13 @@ A native Linux application to control your AirPods, with support for:
6666
- Switch between noise control modes
6767
- View battery levels
6868
- Control playback
69+
70+
## Hearing Aid
71+
72+
To use hearing aid features, you need to have an audiogram. To enable/disable hearing aid, you can use the toggle in the main app. But, to adjust the settings and set the audiogram, you need to use a different script which is located in this folder as `hearing_aid.py`. You can run it with:
73+
74+
```bash
75+
python3 hearing_aid.py
76+
```
77+
78+
The script will load the current settings from the AirPods and allow you to adjust them. You can set the audiogram by providing the values for 8 frequencies (250Hz, 500Hz, 1kHz, 2kHz, 3kHz, 4kHz, 6kHz, 8kHz) for both left and right ears. There are also options to adjust amplification, balance, tone, ambient noise reduction, own voice amplification, and conversation boost.

linux/hearing-aid-adjustments.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def __init__(self, mac_address):
282282
self.debounce_timer = QTimer()
283283
self.debounce_timer.setSingleShot(True)
284284
self.debounce_timer.timeout.connect(self.send_settings)
285-
logging.info("HearingAidApp initialized")
285+
logging.info("HearingAidConfig initialized")
286286

287287
self.init_ui()
288288
self.connect_att()
@@ -350,6 +350,14 @@ def init_ui(self):
350350
self.conv_checkbox = QCheckBox("Conversation Boost")
351351
layout.addWidget(self.conv_checkbox)
352352

353+
# Own Voice Amplification
354+
self.own_voice_slider = QSlider(Qt.Horizontal)
355+
self.own_voice_slider.setRange(0, 100)
356+
self.own_voice_slider.setValue(50)
357+
layout.addWidget(QLabel("Own Voice Amplification"))
358+
# layout.addWidget(self.own_voice_slider) # seems to have no effect
359+
360+
353361
# Connect signals
354362
for input_box in self.left_eq_inputs + self.right_eq_inputs:
355363
input_box.textChanged.connect(self.on_value_changed)
@@ -358,6 +366,7 @@ def init_ui(self):
358366
self.tone_slider.valueChanged.connect(self.on_value_changed)
359367
self.anr_slider.valueChanged.connect(self.on_value_changed)
360368
self.conv_checkbox.stateChanged.connect(self.on_value_changed)
369+
self.own_voice_slider.valueChanged.connect(self.on_value_changed)
361370

362371
self.setLayout(layout)
363372
logging.debug("UI initialized")
@@ -394,6 +403,7 @@ def on_update_ui(self, settings):
394403
self.tone_slider.setValue(int(settings.left_tone * 100))
395404
self.anr_slider.setValue(int(settings.left_ambient_noise_reduction * 100))
396405
self.conv_checkbox.setChecked(settings.left_conversation_boost)
406+
self.own_voice_slider.setValue(int(settings.own_voice_amplification * 100))
397407

398408
for i, value in enumerate(settings.left_eq):
399409
self.left_eq_inputs[i].setText(f"{value:.2f}")
@@ -411,6 +421,7 @@ def send_settings(self):
411421
tone = self.tone_slider.value() / 100.0
412422
anr = self.anr_slider.value() / 100.0
413423
conv = self.conv_checkbox.isChecked()
424+
own_voice = self.own_voice_slider.value() / 100.0
414425

415426
left_amp = amp + (0.5 - balance) * amp * 2 if balance < 0 else amp
416427
right_amp = amp + (balance - 0.5) * amp * 2 if balance > 0 else amp
@@ -420,7 +431,7 @@ def send_settings(self):
420431

421432
settings = HearingAidSettings(
422433
left_eq, right_eq, left_amp, right_amp, tone, tone,
423-
conv, conv, anr, anr, amp, balance, 0.5
434+
conv, conv, anr, anr, amp, balance, own_voice
424435
)
425436
threading.Thread(target=send_hearing_aid_settings, args=(self.att_manager, settings)).start()
426437

@@ -430,11 +441,16 @@ def closeEvent(self, event):
430441
event.accept()
431442

432443
if __name__ == "__main__":
444+
mac = None
433445
if len(sys.argv) != 2:
434446
logging.error("Usage: python hearing-aid-adjustments.py <MAC_ADDRESS>")
435-
print("Usage: python hearing-aid-adjustments.py <MAC_ADDRESS>")
436447
sys.exit(1)
437448
mac = sys.argv[1]
449+
mac_regex = r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
450+
import re
451+
if not re.match(mac_regex, mac):
452+
logging.error("Invalid MAC address format")
453+
sys.exit(1)
438454
logging.info(f"Starting app with MAC: {mac}")
439455
app = QApplication(sys.argv)
440456

0 commit comments

Comments
 (0)