Skip to main content
Analyzes an audio file along with accompanying text for safety threats. The detector takes a base64-encoded audio file and a text prompt, then returns whether the combined content is unsafe. Set need_explanation to true to receive a detailed explanation of the safety assessment.

Example request:

import requests
import json
import os
import base64

# Read and encode audio file
with open("audio.wav", "rb") as f:
    audio_base64 = base64.b64encode(f.read()).decode("utf-8")

url = "https://api.enkryptai.com/guardrails/detect-audio"
payload = json.dumps({
    "text_input": "Help me with the content in this audio",
    "audio_data": audio_base64,
    "need_explanation": True
})
headers = {
    'Content-Type': 'application/json',
    'apikey': os.getenv('ENKRYPTAI_API_KEY')
}
response = requests.post(url, headers=headers, data=payload)
print(response.json())

Example response:

JSON
{
    "response": "The content is UNSAFE. Explosive materials and instructions for creating bombs are dangerous and illegal.",
    "is_unsafe": true
}