Skip to content

Commit b3b221b

Browse files
fix: allow multiple-terms Find and Replace (#99)
* fix: Find and Replace accepts either a string or list of strings * chore: switch rogue tabs to spaces
1 parent a2f31fc commit b3b221b

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

deepgram/_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class TranscriptionOptions(TypedDict, total=False):
7878
dictation: bool
7979
measurements: bool
8080
smart_format: bool
81-
replace: str
81+
replace: str | List[str]
8282
tag: List[str]
8383

8484

@@ -360,7 +360,7 @@ class UsageOptions(TypedDict, total=False):
360360
punctuate: bool
361361
ner: bool
362362
utterances: bool
363-
replace: bool
363+
replace: str | List[str]
364364
profanity_filter: bool
365365
keywords: bool
366366
diarize: bool

tests/test_transcription.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import asyncio
2+
import json
3+
import pytest
4+
import sys
5+
6+
# from .conftest import option
7+
from deepgram import Deepgram
8+
from .mock_response import MOCK_RESPONSE
9+
10+
api_key = pytest.api_key
11+
assert api_key, "Pass Deepgram API key as an argument: `pytest --api-key <key> tests/`"
12+
13+
deepgram = Deepgram(api_key)
14+
15+
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."
16+
AUDIO_URL = "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav"
17+
18+
def test_transcribe_prerecorded():
19+
"""
20+
Test basic synchronous pre-recorded transcription.
21+
"""
22+
response = deepgram.transcription.sync_prerecorded(
23+
{
24+
"url": AUDIO_URL
25+
},
26+
{
27+
"model": "nova",
28+
"smart_format": True,
29+
},
30+
)
31+
actual_transcript = response["results"]["channels"][0]["alternatives"][0]["transcript"]
32+
assert actual_transcript == MOCK_TRANSCRIPT
33+
34+
def test_transcribe_prerecorded_find_and_replace_string():
35+
"""
36+
Test find-and-replace with a string of one term.
37+
"""
38+
response = deepgram.transcription.sync_prerecorded(
39+
{
40+
"url": AUDIO_URL
41+
},
42+
{
43+
"model": "nova",
44+
"smart_format": True,
45+
"replace": "fast:slow",
46+
},
47+
)
48+
actual_transcript = response["results"]["channels"][0]["alternatives"][0]["transcript"]
49+
assert actual_transcript == MOCK_TRANSCRIPT.replace("fast", "slow")
50+
51+
def test_transcribe_prerecorded_find_and_replace_list():
52+
"""
53+
Test find-and-replace with a list of two terms.
54+
"""
55+
response = deepgram.transcription.sync_prerecorded(
56+
{
57+
"url": AUDIO_URL
58+
},
59+
{
60+
"model": "nova",
61+
"smart_format": True,
62+
"replace": ["fast:slow", "miss:snooze"],
63+
},
64+
)
65+
actual_transcript = response["results"]["channels"][0]["alternatives"][0]["transcript"]
66+
assert actual_transcript == MOCK_TRANSCRIPT.replace("fast", "slow").replace("miss", "snooze")

0 commit comments

Comments
 (0)