Dogfennaeth API

Cyfuno TTS.ai â'ch rhaglenni gyda'n API REST. Fformat cydnaws â OpenAI ar gyfer symud hawdd.

API REST Cydnaws OpenAI Ymateb JSON Cynhaliaeth Llif

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

Mae angen dilysiant ar bob cais API drwy tocyn Bearer yn y Authorization pennawd.

Pennawd HTTP
Authorization: Bearer sk-tts-your-api-key-here
Cadw eich allwedd API yn gyfrinachol. Peidiwch â'i rannu mewn cod ar ochr y cleient, storfeydd cyhoeddus, neu gofnodion. Cylchdroi allweddi'n rheolaidd o'ch gosodiadau cyfrif.

URL Sail

URL Sail: https://api.tts.ai/v1/

Mae pob diwedd-bwynt yn gysylltiedig â'r LAU sylfaenol hwn. Er enghraifft, y diwedd-bwynt TTS yw:

POST https://api.tts.ai/v1/tts/

Terfynau Cyfradd

Mae terfynau cyflymder API yn amrywio yn ôl y cynllun:

Cynllun Cais/mun Cyfunol Uchafswm hyd testun
Pro 60 5 5000 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

POST /v1/tts/

Trosi testun i sain siarad. Dychwelyd ffeil sain yn y fformat gofynnol.

Corff y Cais

ParamedrauMathAngenrheidiolDisgrifiad
model string _Yw Dynodiad y model (e.e. kokoro, chatterbox, piper)
text string _Yw Testun i'w drosi i lais (uchafswm o 5,000 o nodau ar gyfer Pro, 50,000 ar gyfer Enterprise)
voice string _Yw Dynodiad llais (defnyddiwch /v1/voices/ i rhestru'r lleisiau sydd ar gael)
format string _Na Fformat allbwn: mp3 (rhagosodedig), wav, flac, ogg
speed float _Na Ffactor cyflymder siarad. Rhagosodedig: 1.0. Amrediad: 0.5 i 2.0
language string _Na Côd iaith (e.e. en, es). Yn cael ei ganfod yn awtomatig os gadewir allan.
stream boolean _Na Galluogi ymateb llif. Rhagosodedig: false

Cais Enghreifftiol

cURL
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

Ymateb

Dychwelyd y ffeil sain fel data deuaidd gyda'r pennawd Content-Type priodol (audio/mpeg, audio/wav, ac ati).

Penawdau Ymateb
Content-Type: audio/mpeg
Content-Length: 48256
X-Credits-Used: 2
X-Credits-Remaining: 498

Lleferydd i DestunName

POST /v1/stt/

Trawsnewid sain i destun. Cynhelir 99 iaith gyda darganfod awtomatig.

Corff y Cais (multipart/form-data)

ParamedrauMathAngenrheidiolDisgrifiad
file file _Yw Ffeil sain (MP3, WAV, FLAC, OGG, M4A, MP4, WebM). Uchafswm 100MB.
model string _Na Model STT: whisper (rhagosodedig), faster-whisper, sensevoice
language string _Na Côd iaith. auto ar gyfer darganfod yn awtomatig (rhagosodedig).
timestamps boolean _Na Cynnwys stampiau amser lefel gair. Rhagosodedig: false
diarize boolean _Na Galluogi diareiddio siaradwyr. Rhagosodedig: false

Ymateb

Ymateb JSON
{
  "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

POST /v1/tts/clone/

Creu siarad mewn llais clônedig. Lawrlwytho sain a testun cyfeirio.

Corff y Cais (multipart/form-data)

ParamedrauMathAngenrheidiolDisgrifiad
reference_audio file _Yw Sain llais cyfeirio (argymhellir 10-30 eiliad). Uchafswm 20MB.
text string _Yw Testun i'w ddweud yn y llais clonedig.
model string _Na Model clôn: chatterbox (rhagosodedig), cosyvoice2, gpt-sovits
format string _Na Fformat allbwn: mp3 (rhagosodedig), wav, flac
language string _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

POST /v1/voice-convert/

Trosi sain i swnio fel llais gwahanol. Lanlwytho'r sain ffynhonnell a dewis llais cyrchfan.

Corff y Cais (multipart/form-data)

ParamedrauMathAngenrheidiolDisgrifiad
file file _Yw Ffeil sain ffynhonnell (MP3, WAV, FLAC). Uchafswm 50MB.
target_voice string _Yw Dynodiad llais targed i'w drosi i (defnyddiwch /v1/voices/ i rhestru'r lleisiau sydd ar gael)
model string _Na Model trawsnewid llais: openvoice (rhagosodedig), knn-vc
format string _Na Fformat allbwn: wav (rhagosodedig), mp3, flac

Cais Enghreifftiol

cURL
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

POST /v1/speech-translate/

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)

ParamedrauMathAngenrheidiolDisgrifiad
file file _Yw Ffeil sain ffynhonnell yn yr iaith wreiddiol. Uchafswm 100MB.
target_language string _Yw Côd iaith cyrchfan (e.e. es, fr, de, ja)
voice string _Na Y llais ar gyfer yr allbwn cyfieithiad. Dewisir yn ymysgogol os anwybyddir.
preserve_voice boolean _Na Ceisio cadw'r siaradwr gwreiddiol

Ymateb

Ymateb JSON
{
  "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

POST /v1/speech-to-speech/

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)

ParamedrauMathAngenrheidiolDisgrifiad
file file _Yw Ffeil sain siarad ffynhonnell. Uchafswm 50MB.
voice string _Yw Dynodiad llais targed ar gyfer y siarad allbwn
model string _Na Model: openvoice (rhagosodedig), chatterbox
emotion string _Na Targed teimlad: neutral, happy, sad, angry, excited
speed float _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.

POST /v1/audio/enhance/

Uwchraddio ansawdd sain: dileu sŵn, uwchraddio clirwch, uwch-ddealltwriaeth.

file fileFfeil sain i'w gwella
denoise booleanGalluogi dileu sŵn (rhagosodedig: gwir)
enhance_clarity booleanCynyddu clirder siarad (rhagosodedig: gwir)
super_resolution booleanUwchraddio ansawdd sain (rhagosodedig: ffug)
strength integer1- 3 (ysgafn, canolig, cryf). Rhagosodedig: 2
POST /v1/audio/separate/

Gwahanu cerddoriaeth gerddorol o gerddoriaeth offerynnol (dileu cerddoriaeth gerddorol) neu rannu'r cerddoriaeth yn ddarnau.

file fileFfeil sain i'w gwahanu
model stringdemucs (rhagosodedig) neu spleeter
stems integerNifer o ddarnau: 2, 4, 5, neu 6 (rhagosodedig: 2)
format stringFformat allbwn: wav, mp3, flac
POST /v1/audio/dereverb/

Gwaredu adlewyrchiad o recordiadau sain.

file fileFfeil sain i'w phrosesu
type stringecho or reverb (default: both)
intensity integer1-5 (default: 3)
POST /v1/audio/analyze/ Rhydd

Dadansoddi sain i ganfod bysell, BPM, a llofnod amser.

file fileFfeil sain i'w dadansoddi
Ymateb
{
  "key": "C",
  "scale": "Major",
  "bpm": 120.0,
  "time_signature": "4/4",
  "camelot": "8B",
  "compatible_keys": ["C Major", "G Major", "F Major", "A Minor"]
}
POST /v1/audio/convert/ Rhydd

Trosi sain rhwng fformatau.

file fileFfeil sain i drosi
format stringFformat cyrchfan: mp3, wav, flac, ogg, m4a, aac
bitrate integerCyfradd did allbwn mewn kbps: 64, 128, 192, 256, 320
sample_rate integerCyfradd samplu: 22050, 44100, 48000
channels stringmono neu stereo

Sgwrs LaisName

POST /v1/voice-chat/

Anfon sain neu destun a derbyn ymateb AI gydag iaith synthetig.

Corff y Cais (multipart/form-data neu JSON)

ParamedrauMathAngenrheidiolDisgrifiad
audio file _Na* Mewnbwn sain (neu audio neu text angenrheidiol)
text string _Na* Mewnbwn testun (neu audio neu text angenrheidiol)
voice string _Na Llais ar gyfer ymateb AI. Rhagosodedig: af_bella
tts_model string _Na Model TTS ar gyfer ymateb. Rhagosodedig: kokoro
system_prompt string _Na Ymholiad cysawd addasiedig ar gyfer y AI
conversation_id string _Na Parhau sgwrs sy'n bodoli eisoes

Ymateb

Ymateb JSON
{
  "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
}

Modelau Rhestr

GET /v1/models/

Dychwelyd rhestr o bob model sydd ar gael gyda' u galluoedd.

Ymateb

Ymateb JSON
{
  "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

GET /v1/voices/

Dychwelyd rhestr o' r holl lais sydd ar gael, wedi' u hidlo yn ôl model neu iaith os dymunwch.

Paramedrau Ymholiad

ParamedrauMathDisgrifiad
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

Ymateb JSON
{
  "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
}

Enghreifftiau

Testun i LeferyddComment

Python - requests
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

Python - requests
# 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

Python - requests
# 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

JavaScript - fetch
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

JavaScript - fetch
// 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

cURL
# 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

cURL
# 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

cURL
# 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

cURL
# 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.

Fformat Ymateb Gwall
{
  "error": {
    "code": "insufficient_credits",
    "message": "You do not have enough credits for this request.",
    "credits_required": 4,
    "credits_available": 2
  }
}
Cyflwr HTTPCod GwallDisgrifiad
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 Nid yw mynediad API ar gael ar eich 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.

Webhook Payload
{
  "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"
}
Mae canlyniadau Webhook ar gael i'w lawrlwytho am 24 awr ar ôl eu cwblhau. Gwnewch yn siŵr eich bod yn eu lawrlwytho yn syth.

Para i Adeiladu?

Cael eich allwedd API a dechrau integreiddio TTS.ai i'ch rhaglenni.