音頻
文字轉語音
將文本轉換為語音音頻(返回 MP3 二進制數據)。
POST
/
api
/
v1
/
audio
/
tts
文字轉語音
curl --request POST \
--url https://api.example.com/api/v1/audio/tts \
--header 'Content-Type: application/json' \
--data '
{
"text": "<string>",
"voice": "<string>",
"speed": 123
}
'import requests
url = "https://api.example.com/api/v1/audio/tts"
payload = {
"text": "<string>",
"voice": "<string>",
"speed": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({text: '<string>', voice: '<string>', speed: 123})
};
fetch('https://api.example.com/api/v1/audio/tts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/audio/tts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'text' => '<string>',
'voice' => '<string>',
'speed' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/audio/tts"
payload := strings.NewReader("{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/audio/tts")
.header("Content-Type", "application/json")
.body("{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/audio/tts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}"
response = http.request(request)
puts response.read_body將文本轉換為語音。返回的是原始音頻字節(
audio/mpeg),而不是 JSON。
響應內容是一個二進制 MP3 文件,而不是 JSON 對象。
Content-Type 響應頭為 audio/mpeg。身份驗證
需要提供 Bearer 令牌。詳見身份驗證。請求體
string
必填
要轉換為語音的文本。最多 4,096 個字符。
string
預設值:"theo-voice-classic"
可選的 Theo 語音標識符。省略則使用默認語音。未知的取值會回退到
theo-voice-classic。| 語音 | 特點 |
|---|---|
theo-voice-classic | 中性、多用途——默認音色 |
theo-voice-bright | 明亮、清晰、活潑 |
theo-voice-storyteller | 敍事感強、富有表現力 |
theo-voice-deep | 低沉、權威 |
theo-voice-warm | 温暖、專業 |
theo-voice-soft | 柔和、沉穩 |
number
預設值:"1.0"
播放速度倍率(0.25–4.0)。
請求示例
curl -X POST https://www.hitheo.ai/api/v1/audio/tts \
-H "Authorization: Bearer $THEO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Welcome to Theo. How can I help you today?",
"voice": "theo-voice-warm",
"speed": 1.0
}' \
--output speech.mp3
const audioBuffer = await theo.tts({
text: "Welcome to Theo. How can I help you today?",
voice: "theo-voice-warm",
speed: 1.0,
});
// audioBuffer is an ArrayBuffer — write to file or stream to client
import { writeFileSync } from "fs";
writeFileSync("output.mp3", Buffer.from(audioBuffer));
響應
響應體是原始 MP3 音頻字節。| 響應頭 | 值 |
|---|---|
Content-Type | audio/mpeg |
Content-Length | 文件大小(字節數) |
X-Request-Id | 唯一請求 ID(前綴為 tts_) |
錯誤
| 狀態碼 | 錯誤碼 | 說明 |
|---|---|---|
| 400 | missing_text | 缺少必填的 text 參數 |
| 401 | invalid_api_key | API 密鑰缺失或無效 |
| 502 | tts_provider_error | Theo 語音引擎返回錯誤——請重試 |
| 503 | tts_unavailable | 此實例未配置文字轉語音功能 |
這個頁面有幫助嗎?
文字轉語音
curl --request POST \
--url https://api.example.com/api/v1/audio/tts \
--header 'Content-Type: application/json' \
--data '
{
"text": "<string>",
"voice": "<string>",
"speed": 123
}
'import requests
url = "https://api.example.com/api/v1/audio/tts"
payload = {
"text": "<string>",
"voice": "<string>",
"speed": 123
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({text: '<string>', voice: '<string>', speed: 123})
};
fetch('https://api.example.com/api/v1/audio/tts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/v1/audio/tts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'text' => '<string>',
'voice' => '<string>',
'speed' => 123
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/v1/audio/tts"
payload := strings.NewReader("{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/audio/tts")
.header("Content-Type", "application/json")
.body("{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/v1/audio/tts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"text\": \"<string>\",\n \"voice\": \"<string>\",\n \"speed\": 123\n}"
response = http.request(request)
puts response.read_body