Audio (TTS & STT)
Text-to-speech, speech-to-text, translation, and voice management.
Yunxin mirrors the OpenAI Audio API for text-to-speech and speech-to-text, plus a voice-management
surface for listing, cloning, and designing voices. Discover audio models with the
Models API (GET /v1/models?type=audio_speech or type=audio_transcription).
Text-to-speech (TTS)
POST /v1/audio/speechSynthesizes input text into an audio stream. The response body is the raw audio file (not JSON).
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | TTS model id. |
input | string | Yes | Text to synthesize. |
voice | string | No | Voice id (see Voices). Default alloy. |
response_format | string | No | mp3 (default), opus, aac, flac, wav, or pcm. |
speed | number | No | Playback speed factor, 0.25–4.0. Default 1.0. |
Example
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["YUNXIN_API_KEY"],
base_url="https://api.yuhuanstudio.com/v1",
)
response = client.audio.speech.create(
model="model-id",
voice="nova",
input="Welcome to Yunxin, your unified AI API gateway.",
)
response.stream_to_file("output.mp3")Speech-to-text (STT)
POST /v1/audio/transcriptionsTranscribes audio in its original language. Send the audio file and model as multipart form data.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | STT model id. |
file | file | Yes | Audio file (e.g. mp3, wav, m4a, webm). |
language | string | No | ISO-639-1 code of the source language (improves accuracy). |
prompt | string | No | Optional text to guide style or spelling. |
response_format | string | No | json (default), text, srt, verbose_json, or vtt. |
temperature | number | No | Sampling temperature, 0–1. |
Example
with open("recording.mp3", "rb") as audio_file:
transcript = client.audio.transcriptions.create(
model="model-id",
file=audio_file,
language="en",
)
print(transcript.text)Translation
POST /v1/audio/translationsTranscribes and translates audio into English. Same multipart shape as transcription, minus
language:
with open("chinese_audio.mp3", "rb") as audio_file:
translation = client.audio.translations.create(
model="model-id",
file=audio_file,
)
print(translation.text) # English translationVoices
GET /v1/voiceLists the voices available for a provider (provider query parameter, default openai). Each entry has
an id, name, and type (preset, cloned, or designed). Providers without a native voice catalog
fall back to the standard OpenAI preset voices:
| Voice | Description |
|---|---|
alloy | Neutral |
echo | Male |
fable | British |
onyx | Deep male |
nova | Female |
shimmer | Soft female |
curl "https://api.yuhuanstudio.com/v1/voice?provider=openai" \
-H "Authorization: Bearer $YUNXIN_API_KEY"Clone a voice
POST /v1/voice/cloneCreates a custom voice from a short audio sample (provider-dependent; e.g. MiniMax).
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | No | Voice model. Default minimax-speech. |
name | string | Yes | Name for the cloned voice (1–64 chars). |
audio_sample | string | Yes | Base64-encoded audio sample, 5–30 seconds, low background noise. |
description | string | No | Description of the voice characteristics. |
Design a voice
POST /v1/voice/designGenerates a brand-new voice from a text description.
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | No | Voice model. Default minimax-speech. |
name | string | Yes | Name for the designed voice (1–64 chars). |
description | string | Yes | Text description, e.g. "A warm female voice with a British accent". |
gender | string | No | male, female, or neutral. Default neutral. |
age_group | string | No | young, adult, or senior. Default adult. |
accent | string | No | Accent preference, e.g. "British", "American". |
Both endpoints return a record with id, type, and a status (pending, processing, completed,
failed). Use the returned voice id as the voice value in TTS.
Voice cloning and design are only available on providers that support them. Check provider capabilities via the Models API and the Providers overview.
How is this guide?