Skip to content

Commit edfd3b6

Browse files
Merge pull request #209 from dvonthenen/fix-readme-fill-out-pydocs
Updates to README, examples, and More PyDocs
2 parents faf3eb5 + 264aecb commit edfd3b6

File tree

41 files changed

+676
-1264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+676
-1264
lines changed

README.md

Lines changed: 84 additions & 926 deletions
Large diffs are not rendered by default.

deepgram/audio/microphone/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import logging, verboselogs
66

7+
"""
8+
constants for microphone
9+
"""
710
LOGGING = logging.WARNING
811
CHANNELS = 1
912
RATE = 16000

deepgram/audio/microphone/errors.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
# Use of this source code is governed by a MIT license that can be found in the LICENSE file.
33
# SPDX-License-Identifier: MIT
44

5-
5+
# exceptions for microphone
66
class DeepgramMicrophoneError(Exception):
77
"""
88
Exception raised for known errors related to Microphone library.
99
1010
Attributes:
1111
message (str): The error message describing the exception.
12-
status (str): The HTTP status associated with the API error.
13-
original_error (str - json): The original error that was raised.
1412
"""
15-
1613
def __init__(self, message: str):
1714
super().__init__(message)
1815
self.name = "DeepgramMicrophoneError"

deepgram/audio/microphone/microphone.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from .errors import DeepgramMicrophoneError
1212
from .constants import LOGGING, CHANNELS, RATE, CHUNK
1313

14-
1514
class Microphone:
1615
"""
1716
This implements a microphone for local audio input. This uses PyAudio under the hood.
@@ -25,6 +24,7 @@ def __init__(
2524
chunk=CHUNK,
2625
channels=CHANNELS,
2726
):
27+
# dynamic import of pyaudio as not to force the requirements on the SDK (and users)
2828
import pyaudio
2929

3030
self.logger = logging.getLogger(__name__)
@@ -40,6 +40,9 @@ def __init__(
4040
self.stream = None
4141

4242
def is_active(self):
43+
"""
44+
returns True if the stream is active, False otherwise
45+
"""
4346
self.logger.debug("Microphone.is_active ENTER")
4447
if self.stream is None:
4548
self.logger.error("stream is None")
@@ -52,6 +55,9 @@ def is_active(self):
5255
return
5356

5457
def start(self):
58+
"""
59+
starts the microphone stream
60+
"""
5561
self.logger.debug("Microphone.start ENTER")
5662

5763
if self.stream is not None:
@@ -76,14 +82,17 @@ def start(self):
7682
self.lock = threading.Lock()
7783

7884
self.stream.start_stream()
79-
self.thread = threading.Thread(target=self.processing)
85+
self.thread = threading.Thread(target=self._processing)
8086
self.thread.start()
8187

8288
self.logger.notice("start succeeded")
8389
self.logger.debug("Microphone.start LEAVE")
8490

85-
def processing(self):
86-
self.logger.debug("Microphone.processing ENTER")
91+
def _processing(self):
92+
"""
93+
the main processing loop for the microphone
94+
"""
95+
self.logger.debug("Microphone._processing ENTER")
8796

8897
try:
8998
while True:
@@ -106,15 +115,18 @@ def processing(self):
106115
self.logger.verbose("regular threaded callback")
107116
self.push_callback(data)
108117

109-
self.logger.notice("processing exiting...")
110-
self.logger.debug("Microphone.processing LEAVE")
118+
self.logger.notice("_processing exiting...")
119+
self.logger.debug("Microphone._processing LEAVE")
111120

112121
except Exception as e:
113122
self.logger.error("Error while sending: %s", str(e))
114-
self.logger.debug("Microphone.processing LEAVE")
123+
self.logger.debug("Microphone._processing LEAVE")
115124
raise
116125

117126
def finish(self):
127+
"""
128+
Stops the microphone stream
129+
"""
118130
self.logger.debug("Microphone.finish ENTER")
119131

120132
self.lock.acquire()
@@ -125,7 +137,7 @@ def finish(self):
125137
if self.thread is not None:
126138
self.thread.join()
127139
self.thread = None
128-
self.logger.notice("processing/send thread joined")
140+
self.logger.notice("_processing/send thread joined")
129141

130142
if self.stream is not None:
131143
self.stream.stop_stream()

deepgram/client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ class DeepgramClient:
3939
4040
Methods:
4141
listen: Returns a ListenClient instance for interacting with Deepgram's transcription services.
42-
manage: Returns a ManageClient instance for managing Deepgram resources.
43-
onprem: Returns an OnPremClient instance for interacting with Deepgram's on-premises API.
42+
43+
manage: (Preferred) Returns a Threaded ManageClient instance for managing Deepgram resources.
44+
onprem: (Preferred) Returns an Threaded OnPremClient instance for interacting with Deepgram's on-premises API.
45+
46+
asyncmanage: Returns an (Async) ManageClient instance for managing Deepgram resources.
47+
asynconprem: Returns an (Async) OnPremClient instance for interacting with Deepgram's on-premises API.
4448
"""
4549

4650
def __init__(

deepgram/clients/abstract_async_client.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ class AbstractAsyncRestClient:
2121
url (Dict[str, str]): The base URL for the RESTful API, including any path segments.
2222
headers (Optional[Dict[str, Any]]): Optional HTTP headers to include in requests.
2323
24-
Attributes:
25-
url (Dict[str, str]): The base URL for the RESTful API.
26-
client (httpx.AsyncClient): An asynchronous HTTP client for making requests.
27-
headers (Optional[Dict[str, Any]]): Optional HTTP headers to include in requests.
28-
2924
Exceptions:
3025
DeepgramApiError: Raised for known API errors.
3126
DeepgramUnknownApiError: Raised for unknown API errors.

deepgram/clients/abstract_sync_client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ class AbstractSyncRestClient:
2020
Args:
2121
url (Dict[str, str]): The base URL for the RESTful API, including any path segments.
2222
headers (Optional[Dict[str, Any]]): Optional HTTP headers to include in requests.
23-
24-
Attributes:
25-
url (Dict[str, str]): The base URL for the RESTful API.
26-
client (httpx.AsyncClient): An asynchronous HTTP client for making requests.
27-
headers (Optional[Dict[str, Any]]): Optional HTTP headers to include in requests.
23+
params (Optional[Dict[str, Any]]): Optional query parameters to include in requests.
24+
timeout (Optional[httpx.Timeout]): Optional timeout configuration for requests.
2825
2926
Exceptions:
3027
DeepgramApiError: Raised for known API errors.

deepgram/clients/errors.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ class DeepgramError(Exception):
99
1010
Attributes:
1111
message (str): The error message describing the exception.
12-
status (str): The HTTP status associated with the API error.
1312
"""
14-
1513
def __init__(self, message: str):
1614
super().__init__(message)
1715
self.name = "DeepgramError"
@@ -28,7 +26,6 @@ class DeepgramModuleError(Exception):
2826
Attributes:
2927
message (str): The error message describing the exception.
3028
"""
31-
3229
def __init__(self, message: str):
3330
super().__init__(message)
3431
self.name = "DeepgramModuleError"
@@ -43,7 +40,6 @@ class DeepgramApiError(Exception):
4340
status (str): The HTTP status associated with the API error.
4441
original_error (str - json): The original error that was raised.
4542
"""
46-
4743
def __init__(self, message: str, status: str, original_error=None):
4844
super().__init__(message)
4945
self.name = "DeepgramApiError"
@@ -63,7 +59,6 @@ class DeepgramUnknownApiError(Exception):
6359
message (str): The error message describing the exception.
6460
status (str): The HTTP status associated with the API error.
6561
"""
66-
6762
def __init__(self, message: str, status: str):
6863
super().__init__(message, status)
6964
self.name = "DeepgramUnknownApiError"

deepgram/clients/listen.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717

1818

1919
class ListenClient:
20+
"""
21+
Represents a client for interacting with the Deepgram API.
22+
23+
This class provides a client for making requests to the Deepgram API with various configuration options.
24+
25+
Attributes:
26+
api_key (str): The Deepgram API key used for authentication.
27+
config_options (DeepgramClientOptions): An optional configuration object specifying client options.
28+
29+
Raises:
30+
DeepgramApiKeyError: If the API key is missing or invalid.
31+
32+
Methods:
33+
live: (Preferred) Returns a Threaded LiveClient instance for interacting with Deepgram's transcription services.
34+
prerecorded: (Preferred) Returns an Threaded PreRecordedClient instance for interacting with Deepgram's prerecorded transcription services.
35+
36+
asynclive: Returns an (Async) LiveClient instance for interacting with Deepgram's transcription services.
37+
asyncprerecorded: Returns an (Async) PreRecordedClient instance for interacting with Deepgram's prerecorded transcription services.
38+
"""
2039
def __init__(self, config: DeepgramClientOptions):
2140
self.logger = logging.getLogger(__name__)
2241
self.logger.addHandler(logging.StreamHandler())

deepgram/clients/live/client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,26 @@
77
from .v1.options import LiveOptions as LiveOptionsLatest
88

99
"""
10-
The client.py points to the current supported version in the SDK.
10+
The vX/client.py points to the current supported version in the SDK.
1111
Older versions are supported in the SDK for backwards compatibility.
1212
"""
1313

14-
1514
class LiveOptions(LiveOptionsLatest):
15+
"""
16+
pass through for LiveOptions based on API version
17+
"""
1618
pass
1719

18-
1920
class LiveClient(LiveClientLatest):
2021
"""
2122
Please see LiveClientLatest for details
2223
"""
23-
2424
def __init__(self, config):
2525
super().__init__(config)
2626

27-
2827
class AsyncLiveClient(AsyncLiveClientLatest):
2928
"""
3029
Please see LiveClientLatest for details
3130
"""
32-
3331
def __init__(self, config):
3432
super().__init__(config)

0 commit comments

Comments
 (0)