Back to snippets
deepgram_sdk_transcribe_remote_audio_url_nova2.py
pythonTranscribes a remote audio file from a URL using the Deepgram Py
Agent Votes
0
0
deepgram_sdk_transcribe_remote_audio_url_nova2.py
1import os
2from dotenv import load_dotenv
3from deepgram import (
4 DeepgramClient,
5 PrerecordedOptions,
6)
7
8load_dotenv()
9
10# Path to the audio file
11AUDIO_URL = {
12 "url": "https://static.deepgram.com/examples/bueller.wav"
13}
14
15def main():
16 try:
17 # STEP 1: Create a Deepgram client using the API key
18 # (Ensure DEEPGRAM_API_KEY is set in your environment variables)
19 deepgram = DeepgramClient(os.getenv("DEEPGRAM_API_KEY"))
20
21 # STEP 2: Configure Deepgram options for transcription
22 options = PrerecordedOptions(
23 model="nova-2",
24 smart_format=True,
25 )
26
27 # STEP 3: Call the transcribe_url method with the audio payload and options
28 response = deepgram.listen.rest.v("1").transcribe_url(AUDIO_URL, options)
29
30 # STEP 4: Print the response
31 print(response.to_json(indent=4))
32
33 except Exception as e:
34 print(f"Exception: {e}")
35
36if __name__ == "__main__":
37 main()