From 8363a5c3d48ad783a1ec7697165c81e8fa1fa162 Mon Sep 17 00:00:00 2001 From: David vonThenen <12752197+dvonthenen@users.noreply.github.com> Date: Wed, 3 Jan 2024 18:29:33 -0800 Subject: [PATCH] Missing Values Across Prerecorded/Live Responses --- deepgram/clients/prerecorded/v1/response.py | 32 +++++++-------------- examples/prerecorded/async_url/main.py | 2 +- examples/prerecorded/file/main.py | 8 ++---- examples/prerecorded/url/main.py | 5 ++-- 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/deepgram/clients/prerecorded/v1/response.py b/deepgram/clients/prerecorded/v1/response.py index 7c682503..fb17e27e 100644 --- a/deepgram/clients/prerecorded/v1/response.py +++ b/deepgram/clients/prerecorded/v1/response.py @@ -80,7 +80,7 @@ def __getitem__(self, key): @dataclass_json @dataclass -class SummaryV2: +class SummaryV1: summary: Optional[str] = "" start_word: Optional[float] = 0 end_word: Optional[float] = 0 @@ -92,19 +92,13 @@ def __getitem__(self, key): @dataclass_json @dataclass -class Summaries(SummaryV2): # internal reference to old name - summary: Optional[str] = "" - start_word: Optional[float] = 0 - end_word: Optional[float] = 0 - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] +class Summaries(SummaryV1): # internal reference to old name + pass @dataclass_json @dataclass -class Summary: +class SummaryV2: result: Optional[str] = "" short: Optional[str] = "" @@ -115,13 +109,8 @@ def __getitem__(self, key): @dataclass_json @dataclass -class Summary(Summary): # internal reference to old name - result: Optional[str] = "" - short: Optional[str] = "" - - def __getitem__(self, key): - _dict = self.to_dict() - return _dict[key] +class Summary(SummaryV2): # internal reference to old name + pass @dataclass_json @@ -305,7 +294,7 @@ class Alternative: transcript: Optional[str] = "" confidence: Optional[float] = 0 words: Optional[List[Word]] = None - summaries: Optional[List[SummaryV2]] = None + summaries: Optional[List[SummaryV1]] = None paragraphs: Optional[Paragraphs] = None entities: Optional[List[Entity]] = None translations: Optional[List[Translation]] = None @@ -319,7 +308,7 @@ def __getitem__(self, key): ] if _dict["summaries"] is not None: _dict["summaries"] = [ - SummaryV2.from_dict(summaries) + SummaryV1.from_dict(summaries) for _, summaries in _dict["summaries"].items() ] if _dict["paragraphs"] is not None: @@ -346,6 +335,7 @@ class Channel: search: Optional[List[Search]] = None alternatives: Optional[List[Alternative]] = None detected_language: Optional[str] = "" + language_confidence: Optional[float] = 0 def __getitem__(self, key): _dict = self.to_dict() @@ -366,7 +356,7 @@ def __getitem__(self, key): class Result: channels: Optional[List[Channel]] = None utterances: Optional[List[Utterance]] = None - summary: Optional[Summary] = None + summary: Optional[SummaryV2] = None def __getitem__(self, key): _dict = self.to_dict() @@ -380,7 +370,7 @@ def __getitem__(self, key): for _, utterances in _dict["utterances"].items() ] if _dict["summary"] is not None: - _dict["summary"] = Summary.from_dict(_dict["summary"]) + _dict["summary"] = SummaryV2.from_dict(_dict["summary"]) return _dict[key] diff --git a/examples/prerecorded/async_url/main.py b/examples/prerecorded/async_url/main.py index 3cac48ee..3322ed81 100644 --- a/examples/prerecorded/async_url/main.py +++ b/examples/prerecorded/async_url/main.py @@ -36,7 +36,7 @@ async def transcribe_url(): async def main(): try: response = await transcribe_url() - print(response) + print(response.to_json(indent=4)) except Exception as e: print(f"Exception: {e}") diff --git a/examples/prerecorded/file/main.py b/examples/prerecorded/file/main.py index af67c7eb..72cccd29 100644 --- a/examples/prerecorded/file/main.py +++ b/examples/prerecorded/file/main.py @@ -17,6 +17,7 @@ AUDIO_FILE = "preamble.wav" + def main(): try: # STEP 1 Create a Deepgram client using the API key in the environment variables @@ -41,11 +42,8 @@ def main(): punctuate=True, diarize=True, ) - file_response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options) - - print(f"\n\n{file_response}\n\n") - json = file_response.to_json() - print(f"{json}\n") + response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options) + print(response.to_json(indent=4)) except Exception as e: print(f"Exception: {e}") diff --git a/examples/prerecorded/url/main.py b/examples/prerecorded/url/main.py index b9ec12f0..d94b4ae9 100644 --- a/examples/prerecorded/url/main.py +++ b/examples/prerecorded/url/main.py @@ -14,6 +14,7 @@ "url": "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav" } + def main(): try: # STEP 1 Create a Deepgram client using the API key from environment variables @@ -25,8 +26,8 @@ def main(): smart_format=True, summarize="v2", ) - url_response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options) - print(url_response) + response = deepgram.listen.prerecorded.v("1").transcribe_url(AUDIO_URL, options) + print(response.to_json(indent=4)) except Exception as e: print(f"Exception: {e}")