Skip to content

Commit

Permalink
Merge pull request #467 from dvonthenen/fix-missing-properties
Browse files Browse the repository at this point in the history
Fix Mismatch Structs on STT REST
  • Loading branch information
davidvonthenen authored Sep 26, 2024
2 parents ee4a581 + e20766d commit c2b0790
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 124 deletions.
15 changes: 9 additions & 6 deletions deepgram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@
)
from .client import (
ModelInfo,
Alternative,
Hit,
Search,
Channel,
Word,
)
from .client import (
OpenResponse,
Expand All @@ -92,6 +89,9 @@
# ErrorResponse,
#### unique
ListenWSMetadata,
ListenWSAlternative,
ListenWSChannel,
ListenWSWord,
)

# prerecorded
Expand Down Expand Up @@ -121,6 +121,8 @@
SyncPrerecordedResponse,
#### shared
# Average,
# Alternative,
# Channel,
# Intent,
# Intents,
# IntentsInfo,
Expand All @@ -132,9 +134,8 @@
# Topic,
# Topics,
# TopicsInfo,
# Word,
#### unique
Alternative,
Channel,
Entity,
Hit,
ListenRESTMetadata,
Expand All @@ -150,7 +151,9 @@
Translation,
Utterance,
Warning,
Word,
ListenRESTAlternative,
ListenRESTChannel,
ListenRESTWord,
)

# read
Expand Down
5 changes: 3 additions & 2 deletions deepgram/audio/microphone/microphone.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Microphone: # pylint: disable=too-many-instance-attributes
_is_muted: bool

_asyncio_loop: asyncio.AbstractEventLoop
_asyncio_thread: threading.Thread
_asyncio_thread: Optional[threading.Thread] = None
_exit: threading.Event

_push_callback_org: Optional[Callable] = None
Expand Down Expand Up @@ -142,6 +142,7 @@ def start(self) -> bool:
)
else:
self._logger.verbose("regular threaded callback")
self._asyncio_thread = None
self._push_callback = self._push_callback_org

self._stream = self._audio.open(
Expand Down Expand Up @@ -267,7 +268,7 @@ def finish(self) -> bool:
self._logger.notice("stopping asyncio loop...")
self._asyncio_loop.call_soon_threadsafe(self._asyncio_loop.stop)
self._asyncio_thread.join()
self._asyncio_thread = None # type: ignore
self._asyncio_thread = None
self._logger.notice("_asyncio_thread joined")

self._logger.notice("finish succeeded")
Expand Down
9 changes: 6 additions & 3 deletions deepgram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@
)
from .clients import (
ModelInfo,
Alternative,
Hit,
Search,
Channel,
Word,
)
from .clients import (
OpenResponse,
Expand Down Expand Up @@ -86,6 +83,9 @@
# UnhandledResponse,
#### unique
ListenWSMetadata,
ListenWSAlternative,
ListenWSChannel,
ListenWSWord,
)

# prerecorded
Expand Down Expand Up @@ -154,6 +154,9 @@
Translation,
Utterance,
Warning,
ListenRESTAlternative,
ListenRESTChannel,
ListenRESTWord,
)

# read
Expand Down
9 changes: 6 additions & 3 deletions deepgram/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
# common (shared between listen rest and websocket)
from .common import (
ModelInfo,
Alternative,
Hit,
Search,
Channel,
Word,
)
from .common import (
OpenResponse,
Expand Down Expand Up @@ -124,6 +121,9 @@
Translation,
Utterance,
Warning,
ListenRESTAlternative,
ListenRESTChannel,
ListenRESTWord,
)


Expand All @@ -150,6 +150,9 @@
# UnhandledResponse,
#### uniqye
ListenWSMetadata,
ListenWSWord,
ListenWSAlternative,
ListenWSChannel,
)

## clients
Expand Down
6 changes: 0 additions & 6 deletions deepgram/clients/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
from .v1 import (
BaseResponse as BaseResponseLatest,
ModelInfo as ModelInfoLatest,
Word as WordLatest,
Alternative as AlternativeLatest,
Hit as HitLatest,
Search as SearchLatest,
Channel as ChannelLatest,
)

# rest
Expand Down Expand Up @@ -56,11 +53,8 @@

BaseResponse = BaseResponseLatest
ModelInfo = ModelInfoLatest
Word = WordLatest
Alternative = AlternativeLatest
Hit = HitLatest
Search = SearchLatest
Channel = ChannelLatest

Average = AverageLatest
Intent = IntentLatest
Expand Down
3 changes: 0 additions & 3 deletions deepgram/clients/common/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
from .shared_response import (
BaseResponse,
ModelInfo,
Word,
Alternative,
Hit,
Search,
Channel,
)

from .rest_response import (
Expand Down
64 changes: 0 additions & 64 deletions deepgram/clients/common/v1/shared_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,47 +58,6 @@ class ModelInfo(BaseResponse):
arch: str = ""


@dataclass
class Word(BaseResponse):
"""
Word object
"""

word: str = ""
start: float = 0
end: float = 0
confidence: float = 0
punctuated_word: Optional[str] = field(
default=None, metadata=dataclass_config(exclude=lambda f: f is None)
)
speaker: Optional[int] = field(
default=None, metadata=dataclass_config(exclude=lambda f: f is None)
)
language: Optional[str] = field(
default=None, metadata=dataclass_config(exclude=lambda f: f is None)
)


@dataclass
class Alternative(BaseResponse):
"""
Alternative object
"""

transcript: str = ""
confidence: float = 0
words: List[Word] = field(default_factory=list)
languages: Optional[List[str]] = field(
default=None, metadata=dataclass_config(exclude=lambda f: f is None)
)

def __getitem__(self, key):
_dict = self.to_dict()
if "words" in _dict:
_dict["words"] = [Word.from_dict(words) for words in _dict["words"]]
return _dict[key]


@dataclass
class Hit(BaseResponse):
"""
Expand All @@ -125,26 +84,3 @@ def __getitem__(self, key):
if "hits" in _dict:
_dict["hits"] = [Hit.from_dict(hits) for hits in _dict["hits"]]
return _dict[key]


@dataclass
class Channel(BaseResponse):
"""
Channel object
"""

search: Optional[List[Search]] = field(
default=None, metadata=dataclass_config(exclude=lambda f: f is None)
)
alternatives: List[Alternative] = field(default_factory=list)

def __getitem__(self, key):
_dict = self.to_dict()
if "search" in _dict:
_dict["search"] = [Search.from_dict(search) for search in _dict["search"]]
if "alternatives" in _dict:
_dict["alternatives"] = [
Alternative.from_dict(alternatives)
for alternatives in _dict["alternatives"]
]
return _dict[key]
9 changes: 6 additions & 3 deletions deepgram/clients/listen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@
TopicsInfo,
# between rest and websocket
ModelInfo,
Alternative,
Hit,
Search,
Channel,
Word,
# unique
Entity,
ListenRESTMetadata,
Expand All @@ -70,6 +67,9 @@
Translation,
Utterance,
Warning,
ListenRESTAlternative,
ListenRESTChannel,
ListenRESTWord,
)


Expand All @@ -94,6 +94,9 @@
UnhandledResponse,
# unique
ListenWSMetadata,
ListenWSWord,
ListenWSAlternative,
ListenWSChannel,
)

# clients
Expand Down
19 changes: 12 additions & 7 deletions deepgram/clients/listen/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@
TopicsInfo as TopicsInfoLatest,
# between rest and websocket
ModelInfo as ModelInfoLatest,
Alternative as AlternativeLatest,
Hit as HitLatest,
Search as SearchLatest,
Channel as ChannelLatest,
Word as WordLatest,
# unique
ListenRESTMetadata as ListenRESTMetadataLatest,
Entity as EntityLatest,
Expand All @@ -59,6 +56,9 @@
Translation as TranslationLatest,
Utterance as UtteranceLatest,
Warning as WarningLatest,
ListenRESTAlternative as ListenRESTAlternativeLatest,
ListenRESTChannel as ListenRESTChannelLatest,
ListenRESTWord as ListenRESTWordLatest,
)

# websocket
Expand All @@ -80,6 +80,9 @@
ErrorResponse as ErrorResponseLatest,
UnhandledResponse as UnhandledResponseLatest,
ListenWSMetadata as ListenWSMetadataLatest,
ListenWSAlternative as ListenWSAlternativeLatest,
ListenWSChannel as ListenWSChannelLatest,
ListenWSWord as ListenWSWordLatest,
)

# The vX/client.py points to the current supported version in the SDK.
Expand All @@ -100,12 +103,9 @@
TopicsInfo = TopicsInfoLatest

# between rest and websocket
Alternative = AlternativeLatest
Channel = ChannelLatest
Hit = HitLatest
ModelInfo = ModelInfoLatest
Search = SearchLatest
Word = WordLatest

# websocket common
OpenResponse = OpenResponseLatest
Expand Down Expand Up @@ -152,6 +152,9 @@
Translation = TranslationLatest
Utterance = UtteranceLatest
Warning = WarningLatest
ListenRESTAlternative = ListenRESTAlternativeLatest
ListenRESTChannel = ListenRESTChannelLatest
ListenRESTWord = ListenRESTWordLatest

# websocket
## input
Expand All @@ -166,7 +169,9 @@

## unique
ListenWSMetadata = ListenWSMetadataLatest

ListenWSAlternative = ListenWSAlternativeLatest
ListenWSChannel = ListenWSChannelLatest
ListenWSWord = ListenWSWordLatest

# clients
ListenRESTClient = ListenRESTClientLatest
Expand Down
9 changes: 6 additions & 3 deletions deepgram/clients/listen/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
# between rest and websocket
from ...common import (
ModelInfo,
Alternative,
Hit,
Search,
Channel,
Word,
)

# common websocket
Expand Down Expand Up @@ -99,6 +96,9 @@
Translation,
Utterance,
Warning,
ListenRESTAlternative,
ListenRESTChannel,
ListenRESTWord,
)

# websocket
Expand All @@ -125,4 +125,7 @@
# Word,
#### unique
Metadata as ListenWSMetadata,
ListenWSWord,
ListenWSAlternative,
ListenWSChannel,
)
Loading

0 comments on commit c2b0790

Please sign in to comment.