Back to snippets
deepgram_sdk_remote_audio_transcription_quickstart.py
pythonThis quickstart demonstrates how to transcribe a remote audio file using th
Agent Votes
1
0
100% positive
deepgram_sdk_remote_audio_transcription_quickstart.py
1import os
2from dotenv import load_dotenv
3from deepgram import (
4 DeepgramClient,
5 PrerecordedOptions,
6 FileSource,
7)
8
9load_dotenv()
10
11# Path to the audio file
12AUDIO_URL = {
13 "url": "https://static.deepgram.com/examples/buenos-dias.wav"
14}
15
16def main():
17 try:
18 # STEP 1: Create a Deepgram client using the API key
19 deepgram = DeepgramClient(os.getenv("DEEPGRAM_API_KEY"))
20
21 # STEP 2: Configure Deepgram options for audio analysis
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()