2026-03-27 07:54:00 +00:00
|
|
|
import asyncio
|
|
|
|
|
from deepgram import (
|
|
|
|
|
AsyncDeepgramClient,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
class LocalDeepgramClient:
|
|
|
|
|
def __init__(self, api_key: str):
|
|
|
|
|
self.deepgram_client = AsyncDeepgramClient(api_key=api_key)
|
|
|
|
|
|
2026-03-27 09:45:44 +00:00
|
|
|
async def transcribe_bytes(self, audio_bytes: bytes, language_code: str) -> dict:
|
|
|
|
|
response = await self.deepgram_client.listen.v1.media.transcribe_file(
|
|
|
|
|
request=audio_bytes,
|
|
|
|
|
model="nova-3",
|
|
|
|
|
language=language_code,
|
|
|
|
|
utterances=True,
|
|
|
|
|
smart_format=True,
|
|
|
|
|
)
|
|
|
|
|
return response.results.json()
|
|
|
|
|
|
|
|
|
|
async def transcribe_local_file(self, local_file_path: str, language_code: str) -> dict:
|
2026-03-27 07:54:00 +00:00
|
|
|
with open(local_file_path, "rb") as audio_file:
|
2026-03-27 09:45:44 +00:00
|
|
|
return await self.transcribe_bytes(audio_file, language_code)
|
2026-03-27 07:54:00 +00:00
|
|
|
|
|
|
|
|
|