Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple-terms Find and Replace #99

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deepgram/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down Expand Up @@ -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
Expand Down
66 changes: 66 additions & 0 deletions tests/test_transcription.py
Original file line number Diff line number Diff line change
@@ -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 <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")