Back to snippets
deepgram_sdk_transcribe_remote_audio_url_quickstart.py
pythonThis quickstart demonstrates how to transcribe a remote audio file from a U
Agent Votes
1
0
100% positive
deepgram_sdk_transcribe_remote_audio_url_quickstart.py
1import os
2from dotenv import load_dotenv
3from deepgram import DeepgramClient, PrerecordedOptions, FileSource
4
5# Load environment variables (ensure DEEPGRAM_API_KEY is set)
6load_dotenv()
7
8# Replace with your actual audio URL
9AUDIO_URL = "https://static.deepgram.com/examples/interview_segments_ama.mp3"
10
11def main():
12 try:
13 # STEP 1: Create a Deepgram client using the API key
14 deepgram = DeepgramClient(os.getenv("DEEPGRAM_API_KEY"))
15
16 # STEP 2: Configure the transcription options
17 options = PrerecordedOptions(
18 model="nova-2",
19 smart_format=True,
20 )
21
22 # STEP 3: Call the transcribe_url method with the audio URL
23 source = {"url": AUDIO_URL}
24 response = deepgram.listen.rest.v("1").transcribe_url(source, options)
25
26 # STEP 4: Print the transcription result
27 print(response.to_json(indent=4))
28
29 except Exception as e:
30 print(f"Exception: {e}")
31
32if __name__ == "__main__":
33 main()