Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

refactor(audio): TYPE_CHECKING import for sounddevice type annotations (H4 nit)

Ruben Lütke932045f298f9
diff --git a/jarvis/audio/capture.py b/jarvis/audio/capture.py
index cff756fb9b..7c61bf3242 100644
--- a/jarvis/audio/capture.py
+++ b/jarvis/audio/capture.py
@@ -12,14 +12,20 @@ from __future__ import annotations
import asyncio
import time
from collections.abc import AsyncIterator
+from typing import TYPE_CHECKING
import numpy as np
from loguru import logger as _log
-try:
+if TYPE_CHECKING:
+ # Type-checkers see the real module so `sd.InputStream` annotations resolve;
+ # at runtime the guarded import below binds sd (or None when absent).
import sounddevice as sd
-except Exception: # noqa: BLE001 — sounddevice/PortAudio (libportaudio2) absent (headless/slim)
- sd = None # type: ignore[assignment]
+else:
+ try:
+ import sounddevice as sd
+ except Exception: # noqa: BLE001 — sounddevice/PortAudio (libportaudio2) absent (headless/slim)
+ sd = None # type: ignore[assignment]
from jarvis.core.protocols import AudioChunk
diff --git a/jarvis/audio/player.py b/jarvis/audio/player.py
index 9032011a7d..b1cbcd1f41 100644
--- a/jarvis/audio/player.py
+++ b/jarvis/audio/player.py
@@ -12,14 +12,19 @@ import asyncio
import logging
import time
from collections.abc import AsyncIterator
-from typing import Any
+from typing import TYPE_CHECKING, Any
import numpy as np
-try:
+if TYPE_CHECKING:
+ # Type-checkers see the real module so `sd.OutputStream` annotations resolve;
+ # at runtime the guarded import below binds sd (or None when absent).
import sounddevice as sd
-except Exception: # noqa: BLE001 — sounddevice/PortAudio (libportaudio2) absent (headless/slim)
- sd = None # type: ignore[assignment]
+else:
+ try:
+ import sounddevice as sd
+ except Exception: # noqa: BLE001 — sounddevice/PortAudio (libportaudio2) absent (headless/slim)
+ sd = None # type: ignore[assignment]
from jarvis.audio import level_tap
from jarvis.core.events import AudioOutFirst