Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvonthenen committed Jun 11, 2024
1 parent 8efe811 commit dff4f4e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
11 changes: 8 additions & 3 deletions deepgram/audio/microphone/microphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import inspect
import asyncio
import threading
from typing import Optional
from typing import Optional, Callable
import logging

from deepgram.utils import verboselogs
Expand Down Expand Up @@ -39,7 +39,7 @@ class Microphone: # pylint: disable=too-many-instance-attributes

def __init__(
self,
push_callback: Optional[object],
push_callback: Optional[Callable] = None,
verbose: int = LOGGING,
rate: int = RATE,
chunk: int = CHUNK,
Expand Down Expand Up @@ -84,7 +84,7 @@ def is_active(self) -> bool:
self._logger.debug("Microphone.is_active LEAVE")
return val

def set_callback(self, push_callback) -> None:
def set_callback(self, push_callback: Callable) -> None:
"""
Set the callback function to be called when data is received.
"""
Expand All @@ -102,6 +102,11 @@ def start(self) -> bool:
self._logger.info("chunk: %d", self._chunk)
self._logger.info("input_device_id: %d", self._input_device_index)

if self._push_callback_org is None:
self._logger.error("start() failed. No callback set.")
self._logger.debug("Microphone.start LEAVE")
return False

if inspect.iscoroutinefunction(self._push_callback_org):
self._logger.verbose("async/await callback - wrapping")
# Run our own asyncio loop.
Expand Down
6 changes: 6 additions & 0 deletions deepgram/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def __init__(
self.logger = verboselogs.VerboseLogger(__name__)
self.logger.addHandler(logging.StreamHandler())

if api_key is None:
api_key = ""

self.verbose = verbose
self.api_key = api_key
self._update_headers(headers=headers)
Expand Down Expand Up @@ -99,6 +102,9 @@ def __init__(
self.logger.addHandler(logging.StreamHandler())
self.logger.setLevel(verboselogs.WARNING) # temporary set for setup

if api_key is None:
api_key = ""

if api_key == "":
api_key = os.getenv("DEEPGRAM_API_KEY", "")
if api_key == "":
Expand Down
5 changes: 3 additions & 2 deletions examples/advanced/prerecorded/direct_invocation/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
load_dotenv()

AUDIO_URL = {
"url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"
"url": "https://static.deepgram.com/examples-tmp/Bueller-Life-moves-pretty-fast.wav"
}


Expand All @@ -38,7 +38,8 @@ def main():

except Exception as e:
print(f"Exception: {e}")
traceback.print_exc()
# enable the following line to print the stack trace
# traceback.print_exc()


if __name__ == "__main__":
Expand Down
2 changes: 0 additions & 2 deletions examples/advanced/streaming/mute-microphone/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def on_message(self, result, **kwargs):
sentence = result.channel.alternatives[0].transcript
if len(sentence) == 0:
return
microphone.mute()
print(f"speaker: {sentence}")
microphone.unmute()

def on_metadata(self, metadata, **kwargs):
print(f"\n\n{metadata}\n\n")
Expand Down

0 comments on commit dff4f4e

Please sign in to comment.