|
| 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