Sprachmodell (GLM-4-Voice)
GLM-4-Voice Sprachdialogmodell mit Unterstützung für Text-zu-Sprache.
API-Endpunkte
POST
/audio/speechText-zu-Sprache
Anfrageparameter
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
model | string | Erforderlich | Modellname: GLM-4-Voice |
input | string | Erforderlich | Text, der in Sprache umgewandelt werden soll |
voice | string | Optional | Stimmauswahl, Standard alloy |
Anfrage-Beispiel
Anfrage-Beispiel
{
"model": "GLM-4-Voice",
"input": "你好,我是智谱AI的语音助手",
"voice": "alloy"
}Antwort-Beispiel
Antwort-Beispiel
(返回音频文件流)Code-Beispiele
Python
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://your-proxy-domain.com/v1"
)
response = client.audio.speech.create(
model="GLM-4-Voice",
voice="alloy",
input="你好,我是智谱AI的语音助手"
)
# 保存音频文件
response.stream_to_file("output.mp3")JavaScript
import OpenAI from 'openai';
import fs from 'fs';
const client = new OpenAI({
apiKey: 'your-api-key',
baseURL: 'https://your-proxy-domain.com/v1'
});
async function generateSpeech() {
const response = await client.audio.speech.create({
model: 'GLM-4-Voice',
voice: 'alloy',
input: '你好,我是智谱AI的语音助手'
});
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync('output.mp3', buffer);
}
generateSpeech();cURL
curl https://your-proxy-domain.com/v1/audio/speech \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "GLM-4-Voice",
"input": "你好,我是智谱AI的语音助手",
"voice": "alloy"
}' \
--output output.mp3