文本转语音
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>"
}
}Authorizations
标准的 HTTP Bearer 认证方式,在 API Keys 页面获取密钥。
Body
application/json
Response
业务处理成功
- 采样率建议设置为24000
The response is of type file.
Was this page helpful?