Audio Inputs
How to send audio files to Infron AI models
Audio Inputs
Sending Audio Files
import requests
import json
import base64
def encode_audio_to_base64(audio_path):
with open(audio_path, "rb") as audio_file:
return base64.b64encode(audio_file.read()).decode('utf-8')
url = "https://llm.onerouter.pro/v1/chat/completions"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# Read and encode the audio file
audio_path = "path/to/your/audio.wav"
base64_audio = encode_audio_to_base64(audio_path)
messages = [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Please transcribe this audio file."
},
{
"type": "input_audio",
"input_audio": {
"data": base64_audio,
"format": "wav"
}
}
]
}
]
payload = {
"model": "{{MODEL}}",
"messages": messages
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())Last updated