Skip to content
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
12 changes: 3 additions & 9 deletions examples/130-telegram-bot-python/src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,15 @@ def transcribe_voice(file_path_or_url: str, api_key: str) -> str | None:
if not audio_bytes:
return None

client = DeepgramClient(api_key)
client = DeepgramClient(api_key=api_key)

# SDK v5 Python: transcribe_file() accepts raw bytes.
# Deepgram auto-detects the audio format from the file header.
# nova-3 is the current flagship model (2025). For phone-call
# audio use nova-3-phonecall; for medical dictation use nova-3-medical.
response = client.listen.v1.media.transcribe_file(
audio_bytes,
request=audio_bytes,
model="nova-3",
# smart_format adds punctuation, capitalisation, and paragraph
# breaks. Adds ~10 ms latency — almost always worth enabling.
smart_format=True,
tag="deepgram-examples",
)
Expand Down Expand Up @@ -115,13 +113,9 @@ async def handle_voice(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
# nova-3 is the current flagship model (2025). For phone-call
# audio use nova-3-phonecall; for medical dictation use nova-3-medical.
response = client.listen.v1.media.transcribe_file(
audio_bytes,
request=audio_bytes,
model="nova-3",
# smart_format adds punctuation, capitalisation, and paragraph
# breaks. Adds ~10 ms latency — almost always worth enabling.
smart_format=True,
# Telegram voice messages are typically one speaker. Enable
# diarize=True if you expect multi-speaker forwarded recordings.
tag="deepgram-examples",
)

Expand Down
13 changes: 4 additions & 9 deletions examples/130-telegram-bot-python/tests/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
# 1 = real test failure (code bug, assertion error, unexpected API response)
# 2 = missing credentials (expected in CI until secrets are configured)
#
# Note: TELEGRAM_BOT_TOKEN is listed in .env.example because it is needed to
# run the bot, but we only need DEEPGRAM_API_KEY to exercise the core
# transcription logic tested here.
env_example = Path(__file__).parent.parent / ".env.example"
required = [
line.split("=")[0].strip()
for line in env_example.read_text().splitlines()
if line and not line.startswith("#") and "=" in line and line[0].isupper()
]
# Only DEEPGRAM_API_KEY is needed for the transcription tests below.
# TELEGRAM_BOT_TOKEN is required to *run* the bot but not to test the
# core transcribe_voice() function we exercise here.
required = ["DEEPGRAM_API_KEY"]
missing = [k for k in required if not os.environ.get(k)]
if missing:
print(f"MISSING_CREDENTIALS: {','.join(missing)}", file=sys.stderr)
Expand Down
Loading