From 7b36571d35964feabeeb8d4e39cd42e055cf679e Mon Sep 17 00:00:00 2001 From: jkroll-deepgram Date: Fri, 30 Jun 2023 16:55:15 -0500 Subject: [PATCH 1/2] Find and Replace accepts either a string or list of strings --- deepgram/_types.py | 4 +-- tests/test_transcription.py | 66 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tests/test_transcription.py diff --git a/deepgram/_types.py b/deepgram/_types.py index cf2d1c63..a3dcc298 100644 --- a/deepgram/_types.py +++ b/deepgram/_types.py @@ -78,7 +78,7 @@ class TranscriptionOptions(TypedDict, total=False): dictation: bool measurements: bool smart_format: bool - replace: str + replace: str | List[str] tag: List[str] @@ -360,7 +360,7 @@ class UsageOptions(TypedDict, total=False): punctuate: bool ner: bool utterances: bool - replace: bool + replace: str | List[str] profanity_filter: bool keywords: bool diarize: bool diff --git a/tests/test_transcription.py b/tests/test_transcription.py new file mode 100644 index 00000000..440fceb5 --- /dev/null +++ b/tests/test_transcription.py @@ -0,0 +1,66 @@ +import asyncio +import json +import pytest +import sys + +# from .conftest import option +from deepgram import Deepgram +from .mock_response import MOCK_RESPONSE + +api_key = pytest.api_key +assert api_key, "Pass Deepgram API key as an argument: `pytest --api-key tests/`" + +deepgram = Deepgram(api_key) + +MOCK_TRANSCRIPT = "Yep. I said it before, and I'll say it again. Life moves pretty fast. You don't stop and look around once in a while. you could miss it." +AUDIO_URL = "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav" + +def test_transcribe_prerecorded(): + """ + Test basic synchronous pre-recorded transcription. + """ + response = deepgram.transcription.sync_prerecorded( + { + "url": AUDIO_URL + }, + { + "model": "nova", + "smart_format": True, + }, + ) + actual_transcript = response["results"]["channels"][0]["alternatives"][0]["transcript"] + assert actual_transcript == MOCK_TRANSCRIPT + +def test_transcribe_prerecorded_find_and_replace_string(): + """ + Test find-and-replace with a string of one term. + """ + response = deepgram.transcription.sync_prerecorded( + { + "url": AUDIO_URL + }, + { + "model": "nova", + "smart_format": True, + "replace": "fast:slow", + }, + ) + actual_transcript = response["results"]["channels"][0]["alternatives"][0]["transcript"] + assert actual_transcript == MOCK_TRANSCRIPT.replace("fast", "slow") + +def test_transcribe_prerecorded_find_and_replace_list(): + """ + Test find-and-replace with a list of two terms. + """ + response = deepgram.transcription.sync_prerecorded( + { + "url": AUDIO_URL + }, + { + "model": "nova", + "smart_format": True, + "replace": ["fast:slow", "miss:snooze"], + }, + ) + actual_transcript = response["results"]["channels"][0]["alternatives"][0]["transcript"] + assert actual_transcript == MOCK_TRANSCRIPT.replace("fast", "slow").replace("miss", "snooze") From ff26876806b23bed09e2cea5b31702554ddb5ed5 Mon Sep 17 00:00:00 2001 From: jkroll-deepgram Date: Wed, 12 Jul 2023 10:44:48 -0500 Subject: [PATCH 2/2] nit: switch rogue tabs to spaces --- tests/test_transcription.py | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/test_transcription.py b/tests/test_transcription.py index 440fceb5..17faf466 100644 --- a/tests/test_transcription.py +++ b/tests/test_transcription.py @@ -20,14 +20,14 @@ def test_transcribe_prerecorded(): Test basic synchronous pre-recorded transcription. """ response = deepgram.transcription.sync_prerecorded( - { + { "url": AUDIO_URL }, - { - "model": "nova", - "smart_format": True, - }, - ) + { + "model": "nova", + "smart_format": True, + }, + ) actual_transcript = response["results"]["channels"][0]["alternatives"][0]["transcript"] assert actual_transcript == MOCK_TRANSCRIPT @@ -36,15 +36,15 @@ def test_transcribe_prerecorded_find_and_replace_string(): Test find-and-replace with a string of one term. """ response = deepgram.transcription.sync_prerecorded( - { + { "url": AUDIO_URL }, - { - "model": "nova", - "smart_format": True, - "replace": "fast:slow", - }, - ) + { + "model": "nova", + "smart_format": True, + "replace": "fast:slow", + }, + ) actual_transcript = response["results"]["channels"][0]["alternatives"][0]["transcript"] assert actual_transcript == MOCK_TRANSCRIPT.replace("fast", "slow") @@ -53,14 +53,14 @@ def test_transcribe_prerecorded_find_and_replace_list(): Test find-and-replace with a list of two terms. """ response = deepgram.transcription.sync_prerecorded( - { + { "url": AUDIO_URL }, - { - "model": "nova", - "smart_format": True, - "replace": ["fast:slow", "miss:snooze"], - }, - ) + { + "model": "nova", + "smart_format": True, + "replace": ["fast:slow", "miss:snooze"], + }, + ) actual_transcript = response["results"]["channels"][0]["alternatives"][0]["transcript"] assert actual_transcript == MOCK_TRANSCRIPT.replace("fast", "slow").replace("miss", "snooze")