Skip to content

Commit a4fd2e8

Browse files
committed
Stop importing pyaudio as soon as the Microphone class is parsed
The import is only used for type checking, so it can instead be put inside an `if TYPE_CHECKING:` block so the optional dependency isn't needed at all times.
1 parent 344cb46 commit a4fd2e8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

deepgram/audio/microphone/microphone.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
import inspect
66
import asyncio
77
import threading
8-
from typing import Optional, Callable
8+
from typing import Optional, Callable, TYPE_CHECKING
99
import logging
1010

1111
from ...utils import verboselogs
1212
from .constants import LOGGING, CHANNELS, RATE, CHUNK
1313

14+
if TYPE_CHECKING:
15+
import pyaudio
16+
1417

1518
class Microphone: # pylint: disable=too-many-instance-attributes
1619
"""
@@ -20,10 +23,8 @@ class Microphone: # pylint: disable=too-many-instance-attributes
2023
_logger: verboselogs.VerboseLogger
2124
_exit: threading.Event
2225

23-
import pyaudio # pylint: disable=import-outside-toplevel
24-
25-
_audio: pyaudio.PyAudio
26-
_stream: pyaudio.Stream
26+
_audio: "pyaudio.PyAudio"
27+
_stream: "pyaudio.Stream"
2728
_chunk: int
2829
_rate: int
2930
_format: int

0 commit comments

Comments
 (0)