Skip to main content
Loading navigation
Back to prompt library

Implement Deepgram Audio Transcription Tool

Linked challenge: Real-Time AI Content Compliance Monitor

Prompt source

implementation15 lines4 sectionsNo variables1 code block
Implement a Python function `transcribe_audio(audio_file_path: str) -> str` that simulates using Deepgram to transcribe an audio file into text. This function should include error handling and return the transcribed text. This will be registered as a tool for your 'Content Ingestor/Analyzer Agent'. Provide the code snippet.

```python
import os
from typing import Dict, Any

# Simulate Deepgram transcription. In a real scenario, you'd use Deepgram SDK.
def transcribe_audio_mock(audio_file_path: str) -> Dict[str, Any]:
    # This is a mock implementation. Replace with actual Deepgram API call.
    if "deepfake_audio.mp3" in audio_file_path:
        return {"transcript": "Just saw a deepfake of the President. It was so convincing, you wouldn't believe it's AI-generated!"}
    elif "normal_audio.mp3" in audio_file_path:
        return {"transcript": "This is a regular news update."}    
    return {"transcript": ""}

# To be used in Claude Agent SDK:
# agent_builder.tool(tool_name="transcribe_audio", description="Transcribes audio content to text.")(transcribe_audio_mock)
```