Text to Speech
API Overview
To simplify the integration of different text-to-speech-creation models (tts), OneRouter provides a unified image API.
API Specification
Generates audio from the input text.
curl https://audio.onerouter.pro/v1/audio/speech \
-H "Content-Type: application/json" \
-H "Authorization: <API_KEY>" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "A cute baby sea otter",
"voice": "alloy"
}' \
--output speech.mp3import os
import json
import requests
API_URL = "https://audio.onerouter.pro/v1/audio/speech"
API_KEY = os.getenv("ONEROUTER_API_KEY")
if not API_KEY:
raise RuntimeError("Please set the ONEROUTER_API_KEY")
payload = {
"model": "gpt-4o-mini-tts",
"input": "A cute baby sea otter.",
"voice": "alloy",
"response_format": "mp3"
}
headers = {
"Authorization": API_KEY,
"Content-Type": "application/json"
}
response = requests.post(API_URL, headers=headers, data=json.dumps(payload))
response.raise_for_status()
out_path = os.path.join(os.path.dirname(__file__), "tts-output.mp3")
with open(out_path, "wb") as f:
f.write(response.content)
print(f"Saved to: {out_path}")<API_KEY>is your API Key generated in API page.modelis the model name, such asgpt-4o-mini-tts, available model list can be access in Model page.The
voiceto use when generating the audio. Supported voices arealloy,ash,ballad,coral,echo,fable,onyx,nova,sage,shimmer, andverse.
Example response
Last updated