Dogfennaeth API
Cyfuno TTS.ai â'ch rhaglenni gyda'n API REST. Fformat cydnaws â OpenAI ar gyfer symud hawdd.
Crynodeb
Mae'r API TTS.ai yn darparu mynediad rhaglennu i bob nodweddion y platfform: cyfansoddiad testun-i-ganu, trosysgrifiad siarad-i-testun, clonio llais, gwella sain, a mwy. Mae'r API yn defnyddio cytundebau REST safonol gyda chorff cais/ateb JSON.
Allwedd API
Nôl eich allwedd API o Gosodiadau Cyfrif. Ar gael ar gynlluniau Pro ac Enterprise.
URL Sail
https://api.tts.ai/v1/
Awdurdodi
Tocyn porthwr drwy Authorization pennawd
Dilysiant
/v1/tts/ gweithio heb unrhyw awdurdodiad, hyd at 5,000 o nodau/diwrnod am bob IP, gan ddefnyddio unrhyw un o'n modelau am ddim (piper, vits, melotts, kokoro). Cofrestru ar gyfer cyfrif am ddim i gael 15,000 o nodau bonws a mynediad i fathau premiwm.
Mae angen dilysiant ar bob cais API drwy tocyn Bearer yn y Authorization pennawd.
Authorization: Bearer sk-tts-your-api-key-here
SDKs
Mae SDKs swyddogol yn gwneud hi'n hawdd i gyd-fynd TTS.ai â'ch rhaglen. Mae'r ddau yn ffynhonnell agored ac ar gael ar GitHub.
Python
pip install ttsai
from tts_ai import TTSClient
client = TTSClient(api_key="sk-tts-...")
audio = client.generate(
text="Hello world!",
model="kokoro"
)
client.save(audio, "output.wav")
JavaScript / Node.js
npm install @ttsainpm/ttsai
const { TTSClient } = require('@ttsainpm/ttsai');
const client = new TTSClient({
apiKey: 'sk-tts-...'
});
const audio = await client.generate({
input: 'Hello world!',
model: 'kokoro'
});
await client.saveToFile(audio, 'output.wav');
URL Sail
Mae pob diwedd-bwynt yn gysylltiedig â'r LAU sylfaenol hwn. Er enghraifft, y diwedd-bwynt TTS yw:
Terfynau Cyfradd
Mae terfynau cyflymder API yn amrywio yn ôl y cynllun:
| Cynllun | Cais/mun | Cyfunol | Uchafswm hyd testun |
|---|---|---|---|
| Rhydd | 10 | 2 | 500 o nodau |
| Cychwynnydd | 30 | 3 | 1,000,000 o nodau |
| Pro | 60 | 5 | 1,000,000 o nodau |
| Enterprise | 300 | 20 | 50,000 o nodau |
Cynhwysir penawdau terfyn cyflymder mewn pob ymateb: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset.
Costiau Credyd
| Gwasanaeth | Cost | Uned |
|---|---|---|
| TTS (Modelau am ddim: Piper, VITS, MeloTTS) | 1 credyd | bob 1,000 o nodau |
| TTS (Modelau safonol: Kokoro, CosyVoice 2, ac ati) | 2 credyd | bob 1,000 o nodau |
| TTS (Modelau premiwm: Tortoise, Chatterbox, ac ati) | 4 credyd | bob 1,000 o nodau |
| Lleferydd i DestunName | 2 credyd | bob munud o sain |
| Clonio Llywio | 4 credyd | bob 1,000 o nodau |
| Newidydd LlygaidName | 3 credyd | bob munud o sain |
| Cynyddu Sain | 2 credyd | bob munud o sain |
| Gwaredu Cerdd / Gwahanu Cerdd | 3-4 credyd | bob munud o sain |
| Cyfieithiad LleferyddName | 5 credyd | bob munud o sain |
| Sgwrs LaisName | 3 credyd | bob tro |
| Canfod Bysellau & BPM | Rhydd | -- |
| Trosiwr SainName | Rhydd | -- |
Testun i LeferyddComment
Trosi testun i sain siarad. Dychwelyd ffeil sain yn y fformat gofynnol.
Corff y Cais
| Paramedrau | Math | Angenrheidiol | Disgrifiad |
|---|---|---|---|
| model | string | & # 160; Na | Dynodiad y model (e.e. kokoro, chatterbox, piper) |
| text | string | & # 160; IeQShortcut | Testun i'w drosi i lais (uchafswm o 5,000 o nodau ar gyfer Pro, 50,000 ar gyfer Enterprise) |
| voice | string | & # 160; IeQShortcut | Dynodiad llais (defnyddiwch /v1/voices/ i rhestru'r lleisiau sydd ar gael) |
| format | string | & # 160; Na | Fformat allbwn: mp3 (rhagosodedig), wav, flac, ogg |
| speed | float | & # 160; Na | Ffactor cyflymder siarad. Rhagosodedig: 1.0. Amrediad: 0.5 i 2.0 |
| language | string | & # 160; Na | Côd iaith (e.e. en, es). Yn cael ei ganfod yn awtomatig os gadewir allan. |
| instructions | string | & # 160; Na | Cynghorion gweithredu/darpariaeth (≤500 o nodau). e.e. \ |
| pronunciations | object | array | & # 160; Na | Trosysgrifo ynganiad ar gais. naill ai {\ |
| stream | boolean | & # 160; Na | Galluogi ymateb llif. Rhagosodedig: false |
Cais Enghreifftiol
curl -X POST https://api.tts.ai/v1/tts/ \
-H "Authorization: Bearer sk-tts-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "kokoro",
"text": "Hello from TTS.ai! This is a test.",
"voice": "af_bella",
"format": "mp3"
}' \
--output output.mp3
Tags SSML
Amlapio rhifau, dyddiadau, arian, rhifau ffôn, a byrddau termau mewn Rhagosodiadau fformat dyddiad i The TTS endpoint queues your request and returns a JSON response with a job UUID. You then poll for the result. Poll this endpoint every 1-2 seconds until Fetch the Streaming alternative: For supported models (Kokoro, MeloTTS), use
dehongli-fel Mewnbwn Llefaru fel cardinal1234one thousand two hundred thirty-four ordinal21twenty-first date1999-12-31trigain- unfed o Ddiweddar, naw deg naw- naw time14:30two thirty PM telephone+1-555-867-5309plus one five five five eight six seven… currency$1,234.56one thousand two hundred thirty-four dollars and fifty-six cents spell-outNASAN A S A mdy ar gyfer Saesneg a dmy ar gyfer eraill; trosglwyddo gyda format=\{
"model": "kokoro",
"voice": "af_bella",
"text": "Your appointment is on <say-as interpret-as=\"date\">2026-04-26</say-as> at <say-as interpret-as=\"time\">14:30</say-as>. Please call <say-as interpret-as=\"telephone\">+1-555-867-5309</say-as> if you need to reschedule."
}Ymateb
Step 1: Submit request
{
"uuid": "77b71db532874ce98e84a69a2d740d4c",
"job_id": "f21316bb-aefa-480d-8523-701d1e3184ce",
"status": "queued",
"credits_used": 11,
"credits_remaining": 15000
}Step 2: Poll for result
status is completed or failed.{
"status": "completed",
"result_url": "https://api.tts.ai/static/downloads/77b71db5.../output.mp3"
}{
"status": "processing"
}Step 3: Download audio
result_url from the completed response to download the audio file.Enghraifft lawn
import requests, time
API_KEY = "sk-tts-your-key"
BASE = "https://api.tts.ai"
# 1. Submit TTS request
resp = requests.post(f"{BASE}/v1/tts/", json={
"model": "kokoro",
"text": "Hello from TTS.ai!",
"voice": "af_bella"
}, headers={"Authorization": f"Bearer {API_KEY}"})
data = resp.json()
uuid = data["uuid"]
# 2. Poll for result
while True:
result = requests.get(f"{BASE}/v1/speech/results/",
params={"uuid": uuid}).json()
if result["status"] == "completed":
# 3. Download audio
audio = requests.get(result["result_url"])
with open("output.mp3", "wb") as f:
f.write(audio.content)
break
elif result["status"] == "failed":
raise Exception(result.get("error", "Generation failed"))
time.sleep(1.5)POST /v1/tts/stream/ for real-time Server-Sent Events (SSE) streaming — no polling needed.
Lleferydd i DestunName
Trawsnewid sain i destun. Cynhelir 99 iaith gyda darganfod awtomatig.
Corff y Cais (multipart/form-data)
| Paramedrau | Math | Angenrheidiol | Disgrifiad |
|---|---|---|---|
| file | file | & # 160; IeQShortcut | Ffeil sain (MP3, WAV, FLAC, OGG, M4A, MP4, WebM). Uchafswm 100MB. |
| model | string | & # 160; Na | Model STT: whisper (rhagosodedig), faster-whisper, sensevoice |
| language | string | & # 160; Na | Côd iaith. auto ar gyfer darganfod yn awtomatig (rhagosodedig). |
| timestamps | boolean | & # 160; Na | Cynnwys stampiau amser lefel gair. Rhagosodedig: false |
| diarize | boolean | & # 160; Na | Galluogi diareiddio siaradwyr. Rhagosodedig: false |
Ymateb
{
"text": "Hello, this is a transcription test.",
"language": "en",
"duration": 3.5,
"segments": [
{
"start": 0.0,
"end": 1.8,
"text": "Hello, this is",
"speaker": "SPEAKER_00"
},
{
"start": 1.8,
"end": 3.5,
"text": "a transcription test.",
"speaker": "SPEAKER_00"
}
]
}
Clonio Llywio
Creu siarad mewn llais clônedig. Lawrlwytho sain a testun cyfeirio.
Corff y Cais (multipart/form-data)
| Paramedrau | Math | Angenrheidiol | Disgrifiad |
|---|---|---|---|
| reference_audio | file | & # 160; IeQShortcut | Sain llais cyfeirio (argymhellir 10-30 eiliad). Uchafswm 20MB. |
| text | string | & # 160; IeQShortcut | Testun i'w ddweud yn y llais clonedig. |
| model | string | & # 160; Na | Model clôn: chatterbox (rhagosodedig), cosyvoice2, gpt-sovits |
| format | string | & # 160; Na | Fformat allbwn: mp3 (rhagosodedig), wav, flac |
| language | string | & # 160; Na | Côd iaith cyrchfan. Rhaid ei gynnal gan y model a ddewiswyd. |
Ymateb
Dychwelyd y ffeil sain fel data deuaidd, yr un fath â' r pwynt diwedd TTS.
Newidydd LlygaidName
Trosi sain i swnio fel llais gwahanol. Lanlwytho'r sain ffynhonnell a dewis llais cyrchfan.
Corff y Cais (multipart/form-data)
| Paramedrau | Math | Angenrheidiol | Disgrifiad |
|---|---|---|---|
| file | file | & # 160; IeQShortcut | Ffeil sain ffynhonnell (MP3, WAV, FLAC). Uchafswm 50MB. |
| target_voice | string | & # 160; IeQShortcut | Dynodiad llais targed i'w drosi i (defnyddiwch /v1/voices/ i rhestru'r lleisiau sydd ar gael) |
| model | string | & # 160; Na | Model trawsnewid llais: openvoice (rhagosodedig), knn-vc |
| format | string | & # 160; Na | Fformat allbwn: wav (rhagosodedig), mp3, flac |
Cais Enghreifftiol
curl -X POST https://api.tts.ai/v1/voice-convert/ \
-H "Authorization: Bearer sk-tts-your-key" \
-F "file=@source_audio.mp3" \
-F "target_voice=af_bella" \
-F "model=openvoice" \
-o converted.wav
Ymateb
Dychwelyd y ffeil sain drosiedig fel data deuaidd.
Cyfieithiad LleferyddName
Cyfieithu sain a lefarwyd o un iaith i'r llall. Cyfuno siarad-i-destun, cyfieithu, a testun-i-ganu mewn galwad sengl.
Corff y Cais (multipart/form-data)
| Paramedrau | Math | Angenrheidiol | Disgrifiad |
|---|---|---|---|
| file | file | & # 160; IeQShortcut | Ffeil sain ffynhonnell yn yr iaith wreiddiol. Uchafswm 100MB. |
| target_language | string | & # 160; IeQShortcut | Côd iaith cyrchfan (e.e. es, fr, de, ja) |
| voice | string | & # 160; Na | Y llais ar gyfer yr allbwn cyfieithiad. Dewisir yn ymysgogol os anwybyddir. |
| preserve_voice | boolean | & # 160; Na | Ceisio cadw'r siaradwr gwreiddiol |
Ymateb
{
"original_text": "Hello, how are you?",
"translated_text": "Hola, como estas?",
"source_language": "en",
"target_language": "es",
"audio_url": "https://api.tts.ai/v1/results/translate_abc123.mp3",
"credits_used": 5
}
Llafar- i- LafarComment
Trawsnewid arddull siarad, teimlad, neu gyflwyno tra'n cadw'r cynnwys. Defnyddiol ar gyfer addasu ton, cyflymder, a mynegiant.
Corff y Cais (multipart/form-data)
| Paramedrau | Math | Angenrheidiol | Disgrifiad |
|---|---|---|---|
| file | file | & # 160; IeQShortcut | Ffeil sain siarad ffynhonnell. Uchafswm 50MB. |
| voice | string | & # 160; IeQShortcut | Dynodiad llais targed ar gyfer y siarad allbwn |
| model | string | & # 160; Na | Model: openvoice (rhagosodedig), chatterbox |
| emotion | string | & # 160; Na | Targed teimlad: neutral, happy, sad, angry, excited
|
| speed | float | & # 160; Na | Addasiad cyflymder. Rhagosodedig: 1.0. Amrediad: 0.5 i 2.0 |
Ymateb
Dychwelyd y ffeil sain trawsnewidedig fel data deuaidd.
Erfyn Sain
Gorffennodau prosesio sain ar gyfer gwella, tynnu llais, rhannu gwreiddiau, a mwy.
Uwchraddio ansawdd sain: dileu sŵn, uwchraddio clirwch, uwch-ddealltwriaeth.
| file file | Ffeil sain i'w gwella |
| denoise boolean | Galluogi dileu sŵn (rhagosodedig: gwir) |
| enhance_clarity boolean | Cynyddu clirder siarad (rhagosodedig: gwir) |
| super_resolution boolean | Uwchraddio ansawdd sain (rhagosodedig: ffug) |
| strength integer | 1- 3 (ysgafn, canolig, cryf). Rhagosodedig: 2 |
Gwahanu cerddoriaeth gerddorol o gerddoriaeth offerynnol (dileu cerddoriaeth gerddorol) neu rannu'r cerddoriaeth yn ddarnau.
| file file | Ffeil sain i'w gwahanu |
| model string | demucs (rhagosodedig) neu spleeter |
| stems integer | Nifer o ddarnau: 2, 4, 5, neu 6 (rhagosodedig: 2) |
| format string | Fformat allbwn: wav, mp3, flac |
Gwaredu adlewyrchiad o recordiadau sain.
| file file | Ffeil sain i'w phrosesu |
| type string | echo or reverb (default: both) |
| intensity integer | 1-5 (default: 3) |
Dadansoddi sain i ganfod bysell, BPM, a llofnod amser.
| file file | Ffeil sain i'w dadansoddi |
{
"key": "C",
"scale": "Major",
"bpm": 120.0,
"time_signature": "4/4",
"camelot": "8B",
"compatible_keys": ["C Major", "G Major", "F Major", "A Minor"]
}
Trosi sain rhwng fformatau.
| file file | Ffeil sain i drosi |
| format string | Fformat cyrchfan: mp3, wav, flac, ogg, m4a, aac |
| bitrate integer | Cyfradd did allbwn mewn kbps: 64, 128, 192, 256, 320 |
| sample_rate integer | Cyfradd samplu: 22050, 44100, 48000 |
| channels string | mono neu stereo |
Sgwrs LaisName
Anfon sain neu destun a derbyn ymateb AI gydag iaith synthetig.
Corff y Cais (multipart/form-data neu JSON)
| Paramedrau | Math | Angenrheidiol | Disgrifiad |
|---|---|---|---|
| audio | file | & # 160; Na* | Mewnbwn sain (neu audio neu text angenrheidiol) |
| text | string | & # 160; Na* | Mewnbwn testun (neu audio neu text angenrheidiol) |
| voice | string | & # 160; Na | Llais ar gyfer ymateb AI. Rhagosodedig: af_bella |
| tts_model | string | & # 160; Na | Model TTS ar gyfer ymateb. Rhagosodedig: kokoro |
| system_prompt | string | & # 160; Na | Ymholiad cysawd addasiedig ar gyfer y AI |
| conversation_id | string | & # 160; Na | Parhau sgwrs sy'n bodoli eisoes |
Ymateb
{
"conversation_id": "conv_abc123",
"user_text": "What is the capital of France?",
"ai_text": "The capital of France is Paris.",
"audio_url": "https://api.tts.ai/v1/audio/tmp/resp_xyz.mp3",
"credits_used": 3
}
Batch TTS
Cyflwyno testunau lluosol ar gyfer creu TTS paralel. Derbyn ad- alwad webhook os dymunwch pan fydd pob swydd wedi' i chwblhau.
Paramedrau
| Paramedrau | Math | Disgrifiad |
|---|---|---|
| texts | array | Array of objects: {text, model, voice}. Max 50 items. |
| webhook_url | string | URL dewisol i'w ddefnyddio i POST canlyniadau pan mae'r batch yn gorffen. |
Ymateb
{
"batch_id": "abc123",
"total": 3,
"completed": 0,
"status": "processing"
}
Cynnydd pleidlais gyda GET /v1/tts/batch/result/?batch_id=abc123
Mewnosod Llywio
Rhag-gyfrifo mewnosod llais o sain cyfeirio. Defnyddio'r embed_id a ddychwelir mewn ceisiadau clonio llais dilynol er mwyn creu'n syth.
Paramedrau
| Paramedrau | Math | Disgrifiad |
|---|---|---|
| file | file | Reference audio file (WAV, MP3, FLAC). |
| model | string | Cloning model (default: chatterbox). Supported: chatterbox, cosyvoice2, openvoice, gpt-sovits, spark, indextts2, qwen3-tts. |
Ymateb
{
"embed_id": "emb_abc123",
"model": "chatterbox",
"duration_ms": 450
}
Gwirio Cyflwr
Gwirio cyflwr y gweinydd GPU, modelau wedi'u llwytho, a maint y ciw. Dim angen dilysiant. Wedi'i gelc am 30 eiliad.
Ymateb
{
"status": "online",
"latency_ms": 45,
"queue_size": 3,
"models_loaded": ["kokoro", "chatterbox", "cosyvoice2"]
}
Modelau Rhestr
Dychwelyd rhestr o bob model sydd ar gael gyda' u galluoedd.
Ymateb
{
"models": [
{
"id": "kokoro",
"name": "Kokoro",
"type": "tts",
"tier": "standard",
"languages": ["en", "ja", "ko", "zh", "fr"],
"supports_cloning": false,
"supports_streaming": true,
"credits_per_1k_chars": 2
},
{
"id": "chatterbox",
"name": "Chatterbox",
"type": "tts",
"tier": "premium",
"languages": ["en"],
"supports_cloning": true,
"supports_streaming": true,
"credits_per_1k_chars": 4
}
]
}
Rhestr Gerddoriaeth
Dychwelyd rhestr o' r holl lais sydd ar gael, wedi' u hidlo yn ôl model neu iaith os dymunwch.
Paramedrau Ymholiad
| Paramedrau | Math | Disgrifiad |
|---|---|---|
| model | string | Hidlo yn ôl ID model (e.e. kokoro) |
| language | string | Hidlo yn ôl cod iaith (e.e. en) |
| gender | string | Hidlo yn ôl rhyw: gwrywaidd, benywaidd, cydnaws |
Ymateb
{
"voices": [
{
"id": "af_bella",
"name": "Bella",
"model": "kokoro",
"language": "en",
"gender": "female",
"preview_url": "https://api.tts.ai/v1/voices/preview/af_bella.mp3"
}
],
"total": 142
}
Isdeitlau (SRT / VTT) newydd
Creu isdeitlau cydweddol ar gyfer unrhyw waith TTS wedi'i gwblhau. Rhedeg alinio chwiban dros y sain a dychwelyd SRT neu WebVTT. Cedwir y canlyniad ar ddisg fel bod ail alwad ar gyfer yr un uuid yn darlleniad disg.
Paramedrau Ymholiad
| Paramedrau | Angenrheidiol | Disgrifiad |
|---|---|---|
| uuid | & # 160; IeQShortcut | Dychwelwyd yr UUID swydd gan /v1/tts/ neu /v1/voice-clone/. |
| format | & # 160; Na | srt (rhagosodedig) neu vtt. |
| download | & # 160; Na | 1 i anfon Content-Disposition: attachment fel bod y porwr yn cadw yn hytrach na dangos. |
| language | & # 160; Na | Cynghoryn i'r model alinio (yn cael ei ganfod yn awtomatig os ei ohirio). |
curl "https://api.tts.ai/v1/speech/subtitles/?uuid=$UUID&format=srt&download=1" -o subtitles.srt
Geiriadur Ynganiad newydd
Dywedwch wrth y peiriant TTS sut i alw geiriau penodol. Caiff cofnodion wedi'u cadw eu defnyddio'n awtomatig ar bob cais TTS rydych yn ei wneud. Terfyn o 200 cofnod ar gyfer pob cyfrif.
Corff y Cais (POST)
| Paramedrau | Math | Disgrifiad |
|---|---|---|
| word | string | Y gair i'w drosysgrifo (e.e. GIF, Anthropic). Cydweddodd ffiniau geiriau. |
| replacement | string | Sut i'w sillafu ar gyfer y model (e.e. jiff, ann THROP ick). |
| language | string | Côd ISO dewisol. Gwag = yn berthnasol i bob iaith. |
| case_sensitive | boolean | false rhagosodedig. Cydweddu llythrennau bach a mawr yn union pan fo true. |
# Save an entry
curl -X POST https://tts.ai/api/v1/pronunciations/ \
-H "Authorization: Bearer sk-tts-..." \
-H "Content-Type: application/json" \
-d '{"word": "GIF", "replacement": "jiff"}'
# List your entries
curl https://tts.ai/api/v1/pronunciations/ -H "Authorization: Bearer sk-tts-..."
# Delete entry by id
curl -X DELETE "https://tts.ai/api/v1/pronunciations/?id=42" -H "Authorization: Bearer sk-tts-..."
Gallwch hefyd basio trosglwyddiadau ar gyfer pob cais heb eu cadw — gan gynnwys pronunciations ar unrhyw alwad /v1/tts/ fel naill ai gwrthrych neu array (gweler y paramedrau diwedd TTS).
Erthygl newydd
Rhowch tag ar unrhyw dudalen erthygl a chaiff ymwelwyr far darllenydd sefydlog sy'n dweud hanes y dudalen ar glicio. Yn canfod corff yr erthygl yn awtomatig, yn cynnal llais / model / lleoliad / lliw canolbwynt addasiedig.
<script src="https://tts.ai/narrator.js"
data-pk="pk-tts-your-publishable-key"
data-voice="af_bella"
data-model="kokoro"
data-extract="auto"
data-position="bottom"
data-color="#e60000"
data-locale="en"></script>
Dewisiadau
| Paramedrau | Disgrifiad |
|---|---|
data-pk | Allwedd gyhoeddadwy (pk-tts-…). Mae cyfyngiadau parth yn cael eu gorfodi drwy faes allowed_domains yr allwedd. |
data-voice | Dynodiad llais. Rhagosodedig af_bella. |
data-model | Dynodiad model TTS. Rhagosodedig kokoro. |
data-extract | auto (rhagosodedig) — ceisio dewiswyr article/main/.post-content/.entry-content, yn dychwelyd i'r clwstwr paragraff mwyaf dwys. Neu drosglwyddo unrhyw ddewisydd CSS i ganolbwyntio ar elfen benodol. |
data-position | bottom (rhagosodedig) neu top. |
data-color | Lliw'r pwyslais (unrhyw liw CSS). Rhagosodedig #e60000. |
data-min-chars / data-max-chars | Hepgor y bar os yw'r erthygl yn hirach na'r nifer lleiaf o nodau (200 fel rhagosodiad). Gorchuddiwch y mewnbwn gyda'r nifer uchaf o nodau (50,000 fel rhagosodiad). |
Celfigyn Botwm Clywed
Mewnosod arddull botwm mewn-lin. Mae'n arlunio wrth ei tag a chwarae darn byr wedi'i ysgogi gan botwm. Siâp gwahanol o'r Narrator Article uchod (sy'n mewnosod bar tudalen-eang yn awtomatig ac yn narllen yr erthygl gyfan).
<script src="https://tts.ai/widget.js"
data-voice="af_bella"
data-model="kokoro"
data-style="full"
data-theme="light"></script>
Llygaid wedi'u Cadw (Clonau Parhaol)
Llwytho sain cyfeirio unwaith, cael voice_id parhaol yn ôl, ac yna cyfeirio at yr id hwnnw mewn ceisiadau TTS yn hytrach na ail-lwytho sain bob galwad. Ideal for high volume integration.
Llwytho i fyny llais
POST
https://tts.ai/api/v1/user-voices/
Angen Dilysiant
Ffurf aml-ran. Maes: ffeil (angenrheidiol, sain 5-30s), enw (angenrheidiol), iaith (dewisol, rhagosodedig en), model (dewisol — dewis yn awtomatig cosyvoice2 ar gyfer zh/ja/ko neu openvoice), consent_confirmed (angenrheidiol, unrhyw werth gwir).
curl -X POST https://tts.ai/api/v1/user-voices/ \
-H "Authorization: Bearer sk-tts-your-key" \
-F "file=@reference.wav" \
-F "name=My Narrator" \
-F "language=en" \
-F "consent_confirmed=true"
# Response:
{
"public_id": "uv_a1b2c3d4e5f6",
"id": 42,
"name": "My Narrator",
"model_name": "openvoice",
"language": "en",
"reference_audio_url": "https://tts.ai/media/user-voices/....wav",
"storage_status": "active",
"created_at": "2026-04-17T03:45:00+00:00"
}
Defnyddio'r llais a gadwyd yn TTS
POST i /api/v1/tts/ (NOD: gwesteiwr VPS gwe, nid api.tts.ai) gyda user_voice_id. Ni lwythwn eich sain a'ch llwybr wedi'u cadw i'r pibell clonio.
curl -X POST https://tts.ai/api/v1/tts/ \
-H "Authorization: Bearer sk-tts-your-key" \
-H "Content-Type: application/json" \
-d '{"text":"Hello from my saved voice","user_voice_id":"uv_a1b2c3d4e5f6"}'
# Returns a queued job — poll /v1/speech/results/?uuid=... for the audio URL.
Rhestr / Dileu
GET https://tts.ai/api/v1/user-voices/ # list your saved voices + quota info
DELETE https://tts.ai/api/v1/user-voices/?public_id=uv_a1b2c3d4e5f6
Archifo / ail-weithredu (am ddim)
Mae lleisiau archifedig yn aros yn eich cyfrif ond ni ellir eu defnyddio yn TTS. Defnyddiol i ddefnyddwyr diwedd-dydd sy'n gorwedd fel bod eich rhestr yn aros yn lân.
POST https://tts.ai/api/v1/user-voices/uv_a1b2c3d4e5f6/archive/
POST https://tts.ai/api/v1/user-voices/uv_a1b2c3d4e5f6/reactivate/
Enghreifftiau
Testun i LeferyddComment
import requests
API_KEY = "sk-tts-your-key"
# Text to Speech
response = requests.post(
"https://api.tts.ai/v1/tts/",
headers={"Authorization": f"Bearer {API_KEY}"},
json={
"model": "kokoro",
"text": "Hello from TTS.ai!",
"voice": "af_bella",
"format": "mp3"
}
)
with open("output.mp3", "wb") as f:
f.write(response.content)
print(f"Credits used: {response.headers.get('X-Credits-Used')}")
Lleferydd i DestunName
# Speech to Text
with open("recording.mp3", "rb") as f:
response = requests.post(
"https://api.tts.ai/v1/stt/",
headers={"Authorization": f"Bearer {API_KEY}"},
files={"file": f},
data={"model": "faster-whisper", "timestamps": "true"}
)
result = response.json()
print(result["text"])
Clonio Llywio
# Voice Cloning
with open("reference.wav", "rb") as ref:
response = requests.post(
"https://api.tts.ai/v1/tts/clone/",
headers={"Authorization": f"Bearer {API_KEY}"},
files={"reference_audio": ref},
data={
"text": "This speech uses a cloned voice.",
"model": "chatterbox"
}
)
with open("cloned_output.mp3", "wb") as f:
f.write(response.content)
Testun i LeferyddComment
const API_KEY = 'sk-tts-your-key';
// Text to Speech
const response = await fetch('https://api.tts.ai/v1/tts/', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'kokoro',
text: 'Hello from TTS.ai!',
voice: 'af_bella',
format: 'mp3'
})
});
const audioBlob = await response.blob();
const audioUrl = URL.createObjectURL(audioBlob);
const audio = new Audio(audioUrl);
audio.play();
Lleferydd i DestunName
// Speech to Text
const formData = new FormData();
formData.append('file', audioFile);
formData.append('model', 'faster-whisper');
const response = await fetch('https://api.tts.ai/v1/stt/', {
method: 'POST',
headers: { 'Authorization': `Bearer ${API_KEY}` },
body: formData
});
const result = await response.json();
console.log(result.text);
Testun i LeferyddComment
# Text to Speech
curl -X POST https://api.tts.ai/v1/tts/ \
-H "Authorization: Bearer sk-tts-your-key" \
-H "Content-Type: application/json" \
-d '{"model":"kokoro","text":"Hello!","voice":"af_bella","format":"mp3"}' \
-o output.mp3
Lleferydd i DestunName
# Speech to Text
curl -X POST https://api.tts.ai/v1/stt/ \
-H "Authorization: Bearer sk-tts-your-key" \
-F "file=@recording.mp3" \
-F "model=faster-whisper" \
-F "timestamps=true"
Clonio Llywio
# Voice Cloning
curl -X POST https://api.tts.ai/v1/tts/clone/ \
-H "Authorization: Bearer sk-tts-your-key" \
-F "reference_audio=@reference.wav" \
-F "text=This uses a cloned voice." \
-F "model=chatterbox" \
-o cloned.mp3
Cynyddu Sain
# Audio Enhancement
curl -X POST https://api.tts.ai/v1/audio/enhance/ \
-H "Authorization: Bearer sk-tts-your-key" \
-F "file=@noisy_audio.mp3" \
-F "denoise=true" \
-F "enhance_clarity=true" \
-o enhanced.mp3
Codau Gwall
Mae pob gwall yn dychwelyd ymateb JSON gyda error maes.
{
"error": {
"code": "insufficient_credits",
"message": "You do not have enough characters for this request.",
"characters_required": 4000,
"characters_available": 2000
}
}
| Cyflwr HTTP | Cod Gwall | Disgrifiad |
|---|---|---|
| 400 | bad_request |
Paramedrau cais annilys. Gwiriwch y neges gwall am fanylion. |
| 401 | unauthorized |
Allwedd API ar goll neu annilys. |
| 402 | insufficient_credits |
Dim digon o gredydau. Prynwch fwy yn /pricing/. |
| 403 | forbidden |
Does gennych chi ddim caniatâd i gyrchu'r adnodd hwn (e.e. pobi swydd defnyddiwr arall). Mae cyrchu API ei hun yn cynnwys pob cynllun. |
| 404 | not_found |
Model neu lais heb ei ganfod. |
| 413 | file_too_large |
Mae' r ffeil a lansiwyd yn fwy na' r terfyn maint. |
| 429 | rate_limited |
Gormod o geisiadau. Gwiriwch benawdau terfyn cyflymder. |
| 500 | internal_error |
Gwall gweinydd. Ceisiwch eto yn ddiweddarach. |
| 503 | model_loading |
Model yn llwytho. Ceisiwch eto mewn ychydig eiliadau. |
Webhooks
Ar gyfer tasgau sy'n rhedeg am amser hir (torri cnwd, TTS batch), gallwch ddarparu paramedr webhook_url. Pan fydd y dasg wedi'i chwblhau, byddwn yn POSTIO'r canlyniad i'ch URL.
{
"event": "task.completed",
"task_id": "task_abc123",
"status": "success",
"result_url": "https://api.tts.ai/v1/results/task_abc123",
"credits_used": 12,
"created_at": "2025-01-15T10:30:00Z",
"completed_at": "2025-01-15T10:30:45Z"
}
Para i Adeiladu?
Cael eich allwedd API a dechrau integreiddio TTS.ai i'ch rhaglenni.