文本转语音
curl --request POST \
--url https://open.bigmodel.cn/api/paas/v4/audio/speech \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "glm-tts",
"input": "你好,今天天气怎么样.",
"voice": "tongtong",
"response_format": "wav"
}
'import requests
url = "https://open.bigmodel.cn/api/paas/v4/audio/speech"
payload = {
"model": "glm-tts",
"input": "你好,今天天气怎么样.",
"voice": "tongtong",
"response_format": "wav"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'glm-tts',
input: '你好,今天天气怎么样.',
voice: 'tongtong',
response_format: 'wav'
})
};
fetch('https://open.bigmodel.cn/api/paas/v4/audio/speech', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://open.bigmodel.cn/api/paas/v4/audio/speech")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"glm-tts\",\n \"input\": \"你好,今天天气怎么样.\",\n \"voice\": \"tongtong\",\n \"response_format\": \"wav\"\n}")
.asString();package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://open.bigmodel.cn/api/paas/v4/audio/speech"
payload := strings.NewReader("{\n \"model\": \"glm-tts\",\n \"input\": \"你好,今天天气怎么样.\",\n \"voice\": \"tongtong\",\n \"response_format\": \"wav\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://open.bigmodel.cn/api/paas/v4/audio/speech",
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([
'model' => 'glm-tts',
'input' => '你好,今天天气怎么样.',
'voice' => 'tongtong',
'response_format' => 'wav'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}"<string>"{
"error": {
"code": "<string>",
"message": "<string>"
}
}语音与音色
文本转语音
使用 GLM-TTS 将文本转换为自然语音,支持多种声音、情感控制和语调调整。点击 Try it 按钮可快速试用。
POST
/
paas
/
v4
/
audio
/
speech
文本转语音
curl --request POST \
--url https://open.bigmodel.cn/api/paas/v4/audio/speech \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "glm-tts",
"input": "你好,今天天气怎么样.",
"voice": "tongtong",
"response_format": "wav"
}
'import requests
url = "https://open.bigmodel.cn/api/paas/v4/audio/speech"
payload = {
"model": "glm-tts",
"input": "你好,今天天气怎么样.",
"voice": "tongtong",
"response_format": "wav"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'glm-tts',
input: '你好,今天天气怎么样.',
voice: 'tongtong',
response_format: 'wav'
})
};
fetch('https://open.bigmodel.cn/api/paas/v4/audio/speech', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://open.bigmodel.cn/api/paas/v4/audio/speech")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"glm-tts\",\n \"input\": \"你好,今天天气怎么样.\",\n \"voice\": \"tongtong\",\n \"response_format\": \"wav\"\n}")
.asString();package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://open.bigmodel.cn/api/paas/v4/audio/speech"
payload := strings.NewReader("{\n \"model\": \"glm-tts\",\n \"input\": \"你好,今天天气怎么样.\",\n \"voice\": \"tongtong\",\n \"response_format\": \"wav\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://open.bigmodel.cn/api/paas/v4/audio/speech",
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([
'model' => 'glm-tts',
'input' => '你好,今天天气怎么样.',
'voice' => 'tongtong',
'response_format' => 'wav'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}"<string>"{
"error": {
"code": "<string>",
"message": "<string>"
}
}Body
application/json
要使用的TTS模型
Available options:
glm-tts 要转换为语音的文本
Maximum string length:
1024生成音频时使用的音色,支持系统音色以及复刻音色两种类型,其中系统音色如下:
tongtong: 彤彤,默认音色
chuichui: 锤锤
xiaochen: 小陈
jam: 动动动物圈jam音色
kazi: 动动动物圈kazi音色
douji: 动动动物圈douji音色
luodo: 动动动物圈luodo音色
Available options:
tongtong, chuichui, xiaochen, jam, kazi, douji, luodo 控制AI生成音频时是否添加水印。去水印操作路径:右上角个人中心-安全管理-去水印管理-打开开关。
true: 默认启用AI生成的显式水印及隐式数字水印,符合政策要求。false: 关闭所有水印,仅对已完成去水印动作的用户生效。
Example:
true
是否启用流式输出。
true: 启用流式输出,模型将通过标准Event Stream逐块返回生成的音频内容。false: 关闭流式输出,模型在生成所有内容后一次性返回所有内容。默认值为false。
语速,默认1.0,取值范围[0.5, 2]
音量,默认1.0,取值范围(0, 10]
仅流式返回时,决定返回的编码格式。默认返回对应音频文件格式的base64字符串。
Available options:
base64, hex 音频输出格式,默认返回pcm格式的文件。流式生成音频时,仅支持返回pcm格式的文件
Available options:
wav, pcm Response
业务处理成功
- 采样率建议设置为24000
The response is of type file.
Was this page helpful?