GLM TTS API 接口、参数 & 代码示例

z-ai/glm-tts

GLM-TTS 是一款以新一代智谱语音大模型为核心的语音合成(TTS)大模型,突破了传统的语音合成框架,通过上下文智能预判文本情绪与语调,显著提升语音自然度与表现力,让合成语音具备真实情感与生命力。

模型 ID
z-ai/glm-tts
模型系列
GLM
更新日期
模型能力
语音合成
模型价格(每千字符)
¥ 0.25
默认音色
tongtong
默认音频格式
wav

GLM TTS 模型介绍:

GLM-TTS 是一款“超拟人”的语音合成大模型。它突破了传统的语音合成框架,让合成的语音具备真实的情感和生命力。

模型概览与技术架构:

  • 核心定位:以新一代智谱语音大模型为核心的语音合成系统。它能够根据上下文智能地预判文本的情绪与语调,显著提升语音的自然度与表现力。
  • 架构设计:采用两阶段生成架构
    • 第一阶段由基于大语言模型(LLM)的架构将输入文本转换为语音 Token 序列。
    • 第二阶段利用 Flow Matching(流匹配)模型将 Token 序列转化为高质量的音频波形(或梅尔谱)。
  • 强化学习优化:在训练中首次引入了基于 GRPO(Group Relative Policy Optimization)的多奖励强化学习方案,在公开评测的“字错误率(CER)”和“情感表达”上取得了开源领域的 SOTA(业内顶尖)表现。

核心功能与特性:

  • 超拟人与情感表达增强:模型具备极强的上下文理解能力,不再是机械式地朗读,而是能够实现“角色化演绎”以及根据内容动态调整情感。
  • 低延迟流式接口(Streaming)
  • 支持非流式和流式两种接口。
  • 流式接口返回响应极快,首帧响应速度可达到 400ms 以内,非常适合实时、低延迟的交互式场景。
  • 动态参数调节:调用时支持随心调节语速(speed)和音量(volume)等参数,以满足复杂的业务场景要求。
  • 多音色与音色复刻(Clone)
  • 平台提供了如 tongtong(彤彤)、chuichui(锤锤)、xiaochen(小陈)等多种系统默认音色,还包括动动动物圈系列(如 jam, kazi, douji, luodo 等)。
  • 配合 glm-tts-clone 模型,它还支持高效的“音色复刻”能力。

主要推荐应用场景:

  • 智能客服:依托超拟人语音的情感适配,提供全链路的柔性服务,降低用户的抵触感。
  • 有声阅读:通过“角色化演绎+情感随内容动态调整”的能力,打造沉浸式的个性化听书体验。
  • 智能交互助手:为智能硬件或车载助理赋予真实情感与场景化语调,使其摆脱冰冷的“工具属性”。
  • 教育领域与职场办公:用于场景化教学(提升学习沉浸感)以及会议纪要转语音、邮件/文档播报等场景。
  • 文旅领域:可替代传统导游,应用于景区智能导览、酒店智能服务等。

API 接口地址:

https://wcode.net/api/gpt/v1/audio/speech

此 API 接口兼容 OpenAI 的 Text-to-Speech 接口规范,可直接使用 OpenAI 的 SDK 来调用。仅需替换以下配置即可:

  1. base_url 替换为 https://wcode.net/api/gpt/v1
  2. api_key 替换为从 https://platform.wcode.net 获取到的 API Key

具体可参考下方的各编程语言代码示例中的 OpenAI SDK 调用示例。

请求方法:

POST

各编程语言代码示例:

# TODO: 以下代码中的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
# 响应为音频二进制,可使用 --output speech.wav 保存文件
curl --request POST 'https://wcode.net/api/gpt/v1/audio/speech' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer API_KEY' \
--output speech.wav \
--data '{
    "model": "z-ai/glm-tts",
    "input": "你好,今天天气怎么样。",
    "voice": "tongtong",
    "response_format": "wav"
}'
import Foundation

let headers = [
  "Authorization": "Bearer API_KEY",  // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
  "content-type": "application/json"
]
let parameters = [
  "model": "z-ai/glm-tts",
  "input": "你好,今天天气怎么样。",
  "voice": "tongtong",
  "response_format": "wav"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://wcode.net/api/gpt/v1/audio/speech")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 60.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else if let data = data {
    try? data.write(to: URL(fileURLWithPath: "speech.wav"))
  }
})

dataTask.resume()
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;

Future<void> main() async {
  var headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer API_KEY'  // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
  };
  var request = http.Request('POST', Uri.parse('https://wcode.net/api/gpt/v1/audio/speech'));
  request.body = json.encode({
    "model": "z-ai/glm-tts",
    "input": "你好,今天天气怎么样。",
    "voice": "tongtong",
    "response_format": "wav"
  });
  request.headers.addAll(headers);

  http.StreamedResponse response = await request.send();

  if (response.statusCode == 200) {
    var bytes = await response.stream.toBytes();
    File('speech.wav').writeAsBytesSync(bytes);
  }
  else {
    print(response.reasonPhrase);
  }
}
require 'uri'
require 'net/http'

url = URI("https://wcode.net/api/gpt/v1/audio/speech")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer API_KEY'  # TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
request["content-type"] = 'application/json'
request.body = "{\"model\":\"z-ai/glm-tts\",\"input\":\"你好,今天天气怎么样。\",\"voice\":\"tongtong\",\"response_format\":\"wav\"}"

response = http.request(request)
File.write("speech.wav", response.body) if response.is_a?(Net::HTTPSuccess)
use serde_json::json;
use reqwest;
use std::fs;

#[tokio::main]
pub async fn main() {
  let url = "https://wcode.net/api/gpt/v1/audio/speech";

  let payload = json!({
    "model": "z-ai/glm-tts",
    "input": "你好,今天天气怎么样。",
    "voice": "tongtong",
    "response_format": "wav"
  });

  let mut headers = reqwest::header::HeaderMap::new();
  headers.insert("Authorization", "Bearer API_KEY".parse().unwrap());  // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
  headers.insert("content-type", "application/json".parse().unwrap());

  let client = reqwest::Client::new();
  let response = client.post(url)
    .headers(headers)
    .json(&payload)
    .send()
    .await
    .unwrap();

  let audio_bytes = response.bytes().await.unwrap();
  fs::write("speech.wav", audio_bytes).unwrap();
}
#include <stdio.h>
#include <curl/curl.h>

static size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) {
  return fwrite(contents, size, nmemb, (FILE *)userp);
}

CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://wcode.net/api/gpt/v1/audio/speech");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Authorization: Bearer API_KEY");  // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
headers = curl_slist_append(headers, "content-type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"model\":\"z-ai/glm-tts\",\"input\":\"你好,今天天气怎么样。\",\"voice\":\"tongtong\",\"response_format\":\"wav\"}");

FILE *fp = fopen("speech.wav", "wb");
curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, fp);

CURLcode ret = curl_easy_perform(hnd);

fclose(fp);
curl_easy_cleanup(hnd);
curl_slist_free_all(headers);
package main

import (
  "fmt"
  "os"
  "strings"
  "net/http"
  "io"
)

func main() {
  url := "https://wcode.net/api/gpt/v1/audio/speech"

  payload := strings.NewReader("{\"model\":\"z-ai/glm-tts\",\"input\":\"你好,今天天气怎么样。\",\"voice\":\"tongtong\",\"response_format\":\"wav\"}")

  req, _ := http.NewRequest("POST", url, payload)

  req.Header.Add("Authorization", "Bearer API_KEY")  // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
  req.Header.Add("content-type", "application/json")

  res, _ := http.DefaultClient.Do(req)

  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)

  os.WriteFile("speech.wav", body, 0644)
  fmt.Println(res.Status)
}
using System.Net.Http.Headers;


var client = new HttpClient();

var request = new HttpRequestMessage(HttpMethod.Post, "https://wcode.net/api/gpt/v1/audio/speech");

request.Headers.Add("Authorization", "Bearer API_KEY");  // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net

request.Content = new StringContent("{\"model\":\"z-ai/glm-tts\",\"input\":\"你好,今天天气怎么样。\",\"voice\":\"tongtong\",\"response_format\":\"wav\"}", null, "application/json");

var response = await client.SendAsync(request);

response.EnsureSuccessStatusCode();

await File.WriteAllBytesAsync("speech.wav", await response.Content.ReadAsByteArrayAsync());
var client = new RestClient("https://wcode.net/api/gpt/v1/audio/speech");

var request = new RestRequest("", Method.Post);

request.AddHeader("Authorization", "Bearer API_KEY");  // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net

request.AddHeader("content-type", "application/json");

request.AddParameter("application/json", "{\"model\":\"z-ai/glm-tts\",\"input\":\"你好,今天天气怎么样。\",\"voice\":\"tongtong\",\"response_format\":\"wav\"}", ParameterType.RequestBody);

var response = client.Execute(request);

if (response.IsSuccessful && response.RawBytes != null)
    await File.WriteAllBytesAsync("speech.wav", response.RawBytes);
const axios = require('axios');
const fs = require('fs');

let data = JSON.stringify({
  "model": "z-ai/glm-tts",
  "input": "你好,今天天气怎么样。",
  "voice": "tongtong",
  "response_format": "wav"
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://wcode.net/api/gpt/v1/audio/speech',
  responseType: 'arraybuffer',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer API_KEY'  // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
  },
  data : data
};

axios.request(config).then((response) => {
  fs.writeFileSync('speech.wav', response.data);
}).catch((error) => {
  console.log(error);
});
import java.nio.file.Files;
import java.nio.file.Path;

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");

RequestBody body = RequestBody.create(mediaType, "{\"model\":\"z-ai/glm-tts\",\"input\":\"你好,今天天气怎么样。\",\"voice\":\"tongtong\",\"response_format\":\"wav\"}");

Request request = new Request.Builder()
  .url("https://wcode.net/api/gpt/v1/audio/speech")
  .post(body)
  .addHeader("Authorization", "Bearer API_KEY")  // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
  .addHeader("content-type", "application/json")
  .build();

try (Response response = client.newCall(request).execute()) {
  if (response.isSuccessful() && response.body() != null) {
    Files.write(Path.of("speech.wav"), response.body().bytes());
  }
}
$client = new \GuzzleHttp\Client();

$headers = [
  'Content-Type' => 'application/json',
  'Authorization' => 'Bearer API_KEY',  // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
];

$body = '{
  "model": "z-ai/glm-tts",
  "input": "你好,今天天气怎么样。",
  "voice": "tongtong",
  "response_format": "wav"
}';

$request = new \GuzzleHttp\Psr7\Request('POST', 'https://wcode.net/api/gpt/v1/audio/speech', $headers, $body);

$response = $client->sendAsync($request)->wait();

file_put_contents('speech.wav', $response->getBody()->getContents());
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://wcode.net/api/gpt/v1/audio/speech",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 5,
  CURLOPT_TIMEOUT => 300,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'model' => 'z-ai/glm-tts',
    'input' => '你好,今天天气怎么样。',
    'voice' => 'tongtong',
    'response_format' => 'wav',
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer API_KEY",  // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
    "content-type: application/json",
  ],
]);

$response = curl_exec($curl);
$error = curl_error($curl);

curl_close($curl);

if ($error) {
  echo "cURL Error #:" . $error;
} else {
  file_put_contents('speech.wav', $response);
}
import requests

url = "https://wcode.net/api/gpt/v1/audio/speech"

payload = {
  "model": "z-ai/glm-tts",
  "input": "你好,今天天气怎么样。",
  "voice": "tongtong",
  "response_format": "wav"
}

headers = {
  "Authorization": "Bearer API_KEY",  # TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
  "content-type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

with open("speech.wav", "wb") as f:
  f.write(response.content)
from openai import OpenAI

client = OpenAI(
  base_url="https://wcode.net/api/gpt/v1",
  api_key="API_KEY"  # TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://platform.wcode.net
)

response = client.audio.speech.create(
  model="z-ai/glm-tts",
  input="你好,今天天气怎么样。",
  voice="tongtong",
  response_format="wav",
)

response.write_to_file("speech.wav")

请求参数:

重要提示:由于模型架构不同,部分参数可能仅适用于特定的模型。

model(模型 ID)

  • 参数:model

  • 必选string

语音合成模型 ID。调用时使用模型详情页的模型 ID。

input(输入文本)

  • 参数:input

  • 必选string

需要进行语音合成的文本内容。

voice(音色)

  • 参数:voice

  • 可选,string

  • 默认:tongtong

语音合成所使用的音色 ID。

生成音频时使用的音色,支持的音色如下:

  • tongtong:彤彤,默认音色
  • chuichui:锤锤
  • xiaochen:小陈
  • jam:动动动物圈 jam 音色
  • kazi:动动动物圈 kazi 音色
  • douji:动动动物圈 douji 音色
  • luodo:动动动物圈 luodo 音色

stream(流式响应)

  • 参数:stream

  • 可选,boolean

  • 取值范围:true | false

  • 默认:false

是否以流式方式返回音频数据。

当前接口暂不支持流式响应;请勿设置 stream: true,否则将返回错误。

volume(音量)

  • 参数:volume

  • 可选,float,(0, 10]

  • 默认:1.0

控制合成语音的音量大小。

speed(语速)

  • 参数:speed

  • 可选,float,0.5 到 2.0

  • 默认:1.0

控制合成语音的语速。

response_format(音频格式)

  • 参数:response_format

  • 可选,string

  • 取值范围:wav | pcm

  • 默认:wav

指定返回音频的编码格式。


以上文档为标准版 API 接口文档,可直接用于项目开发和系统调用。如果标准版 API 接口无法满足您的需求,需要定制开发 API 接口,请联系我们的 IT 技术支持工程师:

(沟通需求✅ → 确认技术方案✅ → 沟通费用与工期✅ → 开发&测试✅ → 验收交付✅ → 维护升级✅)

最受关注模型

DeepSeek V4 Pro

文本生成、深度思考

DeepSeek V4 Flash

文本生成、深度思考

XiaoMi MiMo V2.5 Pro

文本生成、深度思考

Tencent Hunyuan Hy3 Preview

文本生成、深度思考

XiaoMi MiMo V2.5

文本生成、深度思考

最新发布模型

KAT Coder Pro V2.5

文本生成、代码补全

Doubao Seedream 5.0 Pro

图片生成

Qwen3 Rerank

文本重排序

MiMo V2.5 ASR

音频识别

Tongyi GTE Rerank V2

文本重排序

向量化模型

GLM Embedding 3

文本向量化

Qwen3 Embedding 8B

文本嵌入、文本向量化

Doubao Embedding Large Text 250515

文本向量化

Qwen Text Embedding V4

文本向量化

Qwen Text Embedding V1

文本向量化

语音识别模型

MiMo V2.5 ASR

音频识别

Fun ASR Flash

语音识别、方言识别

Qwen3 ASR Flash

语音识别

GLM ASR 2512

语音识别

语音合成模型

CosyVoice V3 Plus

语音合成

CosyVoice V3 Flash

语音合成

GLM TTS

语音合成