音频处理
TTS 文字转语音
将文本转换为自然流畅的语音
POST
/
v1
/
audio
/
speech
curl https://api.qingbo.ai/v1/audio/speech \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"voice": "nova",
"input": "欢迎使用清波 API 文字转语音服务。"
}' \
--output output.wav
from openai import OpenAI
client = OpenAI(
base_url="https://api.qingbo.ai/v1",
api_key="YOUR_API_KEY"
)
response = client.audio.speech.create(
model="gpt-4o-mini-tts",
voice="nova",
input="欢迎使用清波 API 文字转语音服务。",
response_format="wav"
)
response.stream_to_file("output.wav")
import OpenAI from 'openai';
import fs from 'fs';
const client = new OpenAI({
baseURL: 'https://api.qingbo.ai/v1',
apiKey: 'YOUR_API_KEY'
});
const response = await client.audio.speech.create({
model: 'gpt-4o-mini-tts',
voice: 'nova',
input: '欢迎使用清波 API 文字转语音服务。',
response_format: 'wav'
});
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync('output.wav', buffer);
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
)
func main() {
payload := map[string]string{
"model": "gpt-4o-mini-tts",
"voice": "nova",
"input": "欢迎使用清波 API 文字转语音服务。",
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://api.qingbo.ai/v1/audio/speech", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
out, _ := os.Create("output.wav")
defer out.Close()
io.Copy(out, resp.Body)
}
import java.net.http.*;
import java.net.URI;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"model": "gpt-4o-mini-tts",
"voice": "nova",
"input": "欢迎使用清波 API 文字转语音服务。"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.qingbo.ai/v1/audio/speech"))
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<byte[]> response = client.send(request,
HttpResponse.BodyHandlers.ofByteArray());
Files.write(Path.of("output.wav"), response.body());
}
}
同步接口:请求返回的就是音频文件本身,没有
以上之外的参数会返回
task_id,不需要轮询。本端点只服务 gpt-4o-mini-tts;需要歌曲或人声演唱时用 Suno 音乐生成。
curl https://api.qingbo.ai/v1/audio/speech \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"voice": "nova",
"input": "欢迎使用清波 API 文字转语音服务。"
}' \
--output output.wav
from openai import OpenAI
client = OpenAI(
base_url="https://api.qingbo.ai/v1",
api_key="YOUR_API_KEY"
)
response = client.audio.speech.create(
model="gpt-4o-mini-tts",
voice="nova",
input="欢迎使用清波 API 文字转语音服务。",
response_format="wav"
)
response.stream_to_file("output.wav")
import OpenAI from 'openai';
import fs from 'fs';
const client = new OpenAI({
baseURL: 'https://api.qingbo.ai/v1',
apiKey: 'YOUR_API_KEY'
});
const response = await client.audio.speech.create({
model: 'gpt-4o-mini-tts',
voice: 'nova',
input: '欢迎使用清波 API 文字转语音服务。',
response_format: 'wav'
});
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync('output.wav', buffer);
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
)
func main() {
payload := map[string]string{
"model": "gpt-4o-mini-tts",
"voice": "nova",
"input": "欢迎使用清波 API 文字转语音服务。",
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://api.qingbo.ai/v1/audio/speech", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
out, _ := os.Create("output.wav")
defer out.Close()
io.Copy(out, resp.Body)
}
import java.net.http.*;
import java.net.URI;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"model": "gpt-4o-mini-tts",
"voice": "nova",
"input": "欢迎使用清波 API 文字转语音服务。"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.qingbo.ai/v1/audio/speech"))
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<byte[]> response = client.send(request,
HttpResponse.BodyHandlers.ofByteArray());
Files.write(Path.of("output.wav"), response.body());
}
}
请求参数
string
必填
模型 ID:
gpt-4o-mini-tts。string
必填
要转换的文本,最多 4,096 个字符。
string
必填
音色,六种可选:
alloy:中性、平衡echo:男声、沉稳fable:英式、叙述感onyx:男声、深沉nova:女声、有活力shimmer:女声、温柔
string
默认值:"wav"
音频格式:
wav(未压缩)、opus(流媒体)、aac、flac(无损压缩)、pcm(原始音频数据)。number
默认值:"1.0"
语速,取值
1.0。400,不计费。
限制
| 条件 | 限制 |
|---|---|
input 长度 | 最多 4,096 个字符,且不超过 2,000 token |
speed | 取值 1.0 |
| 每次请求 | 返回一个音频文件 |
计费
按输入文本的字符数计费,不收输出费用:音频时长、voice 和 response_format 都不影响价格,字符数是唯一的计费维度,提交前即可确定单次费用。
单价见 GET /v1/models 返回的 price_config,或控制台「模型市场」。计费单位是 quota,500,000 quota = 1 USD,不是美元。
请求失败不计费。
响应
返回音频文件的二进制流,格式由response_format 决定,默认 wav,直接保存为文件即可。出错时返回 JSON 错误对象,不返回音频。
可用模型
| 模型 ID | 说明 |
|---|---|
gpt-4o-mini-tts | OpenAI 当代文字转语音模型,六种音色,五种音频格式 |
当前不支持
instructions:用自然语言指定语气、语速与情绪- 流式返回音频
mp3输出格式
400,不计费。
相关文档
⌘I
curl https://api.qingbo.ai/v1/audio/speech \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"voice": "nova",
"input": "欢迎使用清波 API 文字转语音服务。"
}' \
--output output.wav
from openai import OpenAI
client = OpenAI(
base_url="https://api.qingbo.ai/v1",
api_key="YOUR_API_KEY"
)
response = client.audio.speech.create(
model="gpt-4o-mini-tts",
voice="nova",
input="欢迎使用清波 API 文字转语音服务。",
response_format="wav"
)
response.stream_to_file("output.wav")
import OpenAI from 'openai';
import fs from 'fs';
const client = new OpenAI({
baseURL: 'https://api.qingbo.ai/v1',
apiKey: 'YOUR_API_KEY'
});
const response = await client.audio.speech.create({
model: 'gpt-4o-mini-tts',
voice: 'nova',
input: '欢迎使用清波 API 文字转语音服务。',
response_format: 'wav'
});
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync('output.wav', buffer);
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
)
func main() {
payload := map[string]string{
"model": "gpt-4o-mini-tts",
"voice": "nova",
"input": "欢迎使用清波 API 文字转语音服务。",
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://api.qingbo.ai/v1/audio/speech", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
req.Header.Set("Content-Type", "application/json")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
out, _ := os.Create("output.wav")
defer out.Close()
io.Copy(out, resp.Body)
}
import java.net.http.*;
import java.net.URI;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
String payload = """
{
"model": "gpt-4o-mini-tts",
"voice": "nova",
"input": "欢迎使用清波 API 文字转语音服务。"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.qingbo.ai/v1/audio/speech"))
.header("Authorization", "Bearer YOUR_API_KEY")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload))
.build();
HttpResponse<byte[]> response = client.send(request,
HttpResponse.BodyHandlers.ofByteArray());
Files.write(Path.of("output.wav"), response.body());
}
}