Генерация аудио
Генерация аудио выполняется через POST /api/v1/audios. Запрос сразу отвечает 202, результат забирается поллингом. В SDK OpenAI это client.post("/audios", ...), а не client.audio.speech.create().
Подробно о модальностях каждой модели можно узнать на странице моделей.
Параметры запроса
| Параметр | Тип | Обязательный | Описание |
|---|---|---|---|
| model | string | Да | Название TTS-модели из списка |
| input | string | Да | Текст для озвучки |
| voice | string | Да | Голос озвучки (например: "alloy", "Kore", "eve"). Поддерживаемые значения зависят от модели |
| format | string | Да | Формат аудио (например: "mp3", "wav", "opus", "flac"). Поддерживаемые значения зависят от модели |
| speed | number | Нет | Скорость озвучки (например: 0.25, 1.0, 1.5, 2.0). Поддерживаемые значения зависят от модели |
Пример запроса на генерацию аудио
SDK OpenAI
Python
cURL
PHP
import time
import base64
import httpx
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://ai.mitup.ru/api/v1",
)
response = client.post("/audios",
body={
"model": "grok-tts",
"input": "Озвучь текст: Добро пожаловать в Mitup AI",
"voice": "eve",
"format": "mp3",
},
cast_to=httpx.Response,
)
data = response.json()
task_id = data["id"]
while True:
status_response = client.get(f"/audios/{task_id}", cast_to=httpx.Response)
data = status_response.json()
status = data.get("status")
if status == "completed":
audio_format = data.get("format") or "mp3"
for index, item in enumerate(data.get("data") or []):
filename = f"output_{index}.{audio_format}"
with open(filename, "wb") as f:
f.write(base64.b64decode(item["b64_json"]))
print("Аудио сохранено:", filename)
break
if status == "failed":
print("Ошибка:", data.get("error"))
break
time.sleep(2)import time
import base64
import requests
url = "https://ai.mitup.ru/api/v1/audios"
api_key = "YOUR_API_KEY"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
params = {
"model": "grok-tts",
"input": "Озвучь текст: Добро пожаловать в Mitup AI",
"voice": "eve",
"format": "mp3"
}
response = requests.post(url, json=params, headers=headers)
data = response.json()
task_id = data["id"]
while True:
status_response = requests.get(f"https://ai.mitup.ru/api/v1/audios/{task_id}", headers=headers)
data = status_response.json()
status = data.get("status")
if status == "completed":
audio_format = data.get("format") or "mp3"
for index, item in enumerate(data.get("data") or []):
filename = f"output_{index}.{audio_format}"
with open(filename, "wb") as f:
f.write(base64.b64decode(item["b64_json"]))
print("Аудио сохранено:", filename)
break
if status == "failed":
print("Ошибка:", data.get("error"))
break
time.sleep(2)curl -X POST "https://ai.mitup.ru/api/v1/audios" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "grok-tts",
"input": "Озвучь текст: Добро пожаловать в Mitup AI",
"voice": "eve",
"format": "mp3"
}'
curl -X GET "https://ai.mitup.ru/api/v1/audios/YOUR_TASK_ID" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY"<?php
$url = "https://ai.mitup.ru/api/v1/audios";
$api_key = "YOUR_API_KEY";
$headers = [
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key,
];
$params = [
"model" => "grok-tts",
"input" => "Озвучь текст: Добро пожаловать в Mitup AI",
"voice" => "eve",
"format" => "mp3"
];
$data = json_encode($params, JSON_UNESCAPED_UNICODE);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'mitupai-API-client');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response, true);
$task_id = $response['id'] ?? '';
do {
sleep(2);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'mitupai-API-client');
curl_setopt($ch, CURLOPT_URL, "https://ai.mitup.ru/api/v1/audios/" . $task_id);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$poll = json_decode(curl_exec($ch), true);
curl_close($ch);
$status = $poll['status'] ?? '';
} while (in_array($status, ['pending', 'processing'], true));
if ($status === 'completed') {
$format = $poll['format'] ?? 'mp3';
foreach ($poll['data'] ?? [] as $index => $item) {
$filename = "output_{$index}.{$format}";
file_put_contents($filename, base64_decode($item['b64_json'] ?? ''));
echo "Аудио сохранено: {$filename}\n";
}
} else {
echo "Ошибка: " . json_encode($poll['error'] ?? $poll, JSON_UNESCAPED_UNICODE) . "\n";
}
?>Пример ответа статуса задачи при поллинге:
Ожидание (200)
Успех (200)
Ошибка (4хх, 5xx)
{
"id": "YOUR_TASK_ID",
"status": "pending"
}{
"id": "YOUR_TASK_ID",
"status": "completed",
"created": 1710000000,
"data": [{"b64_json": "..."}],
"format": "mp3",
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"total_tokens": 0
}
}{
"id": "YOUR_TASK_ID",
"created": 1710000000,
"status": "failed",
"error": {
"message": "...",
"type": "server_error",
"code": "500"
}
}Удалить задачу любого типа можно на странице Удаление задачи.