Skip to content

音频 API

Star API 提供兼容 OpenAI Whisper 格式的音频处理接口,支持语音转文字和文字转语音功能。

语音转文字(Speech-to-Text)

请求端点

POST https://star.zhxyclaw.cn/v1/audio/transcriptions

请求参数

参数类型必填说明
filefile音频文件(支持 mp3、mp4、m4a、wav、webm、flac 等格式)
modelstring使用的模型,例如 whisper-1
languagestring音频语言的 ISO 639-1 代码(如 zhen
promptstring提示词,帮助模型更好地识别特定领域的术语
response_formatstring返回格式:json(默认)、textsrtverbose_jsonvtt
temperaturenumber采样温度,范围 0-1

请求示例

curl

bash
curl https://star.zhxyclaw.cn/v1/audio/transcriptions \
  -H "Authorization: Bearer sk-your-api-key" \
  -F file="@audio.mp3" \
  -F model="whisper-1" \
  -F language="zh" \
  -F response_format="json"

Python

python
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://star.zhxyclaw.cn/v1"
)

with open("audio.mp3", "rb") as audio_file:
    transcript = client.audio.transcriptions.create(
        model="whisper-1",
        file=audio_file,
        language="zh",
        response_format="json"
    )

print(transcript.text)

Node.js

javascript
import OpenAI from "openai";
import fs from "fs";

const client = new OpenAI({
  apiKey: "sk-your-api-key",
  baseURL: "https://star.zhxyclaw.cn/v1",
});

const transcription = await client.audio.transcriptions.create({
  model: "whisper-1",
  file: fs.createReadStream("audio.mp3"),
  language: "zh",
  response_format: "json",
});

console.log(transcription.text);

响应格式

json
{
  "text": "这是一段语音识别的结果。"
}

翻译接口

Star API 同样支持音频翻译,将音频内容翻译为英文:

POST https://star.zhxyclaw.cn/v1/audio/translations
bash
curl https://star.zhxyclaw.cn/v1/audio/translations \
  -H "Authorization: Bearer sk-your-api-key" \
  -F file="@audio.mp3" \
  -F model="whisper-1" \
  -F response_format="json"

文字转语音(Text-to-Speech)

请求端点

POST https://star.zhxyclaw.cn/v1/audio/speech

请求参数

参数类型必填说明
modelstringTTS 模型,如 tts-1tts-1-hd
inputstring要转换为语音的文本(最大 4096 字符)
voicestring音色:alloyechofableonyxnovashimmer
response_formatstring音频格式:mp3(默认)、opusaacflacwavpcm
speednumber语速,范围 0.25-4.0,默认 1.0

请求示例

curl

bash
curl https://star.zhxyclaw.cn/v1/audio/speech \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-api-key" \
  -d '{
    "model": "tts-1",
    "input": "你好,欢迎使用 Star API!",
    "voice": "alloy",
    "response_format": "mp3",
    "speed": 1.0
  }' \
  -o output.mp3

Python

python
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://star.zhxyclaw.cn/v1"
)

response = client.audio.speech.create(
    model="tts-1",
    input="你好,欢迎使用 Star API!",
    voice="alloy",
    response_format="mp3",
    speed=1.0
)

response.stream_to_file("output.mp3")

Node.js

javascript
import OpenAI from "openai";
import fs from "fs";

const client = new OpenAI({
  apiKey: "sk-your-api-key",
  baseURL: "https://star.zhxyclaw.cn/v1",
});

const response = await client.audio.speech.create({
  model: "tts-1",
  input: "你好,欢迎使用 Star API!",
  voice: "alloy",
  response_format: "mp3",
  speed: 1.0,
});

const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync("output.mp3", buffer);

音色说明

音色描述
alloy中性、均衡的声音
echo沉稳、深沉的男性声音
fable富有表现力的声音
onyx低沉、有力的男性声音
nova温暖、友好的女性声音
shimmer柔和、温暖的女性声音

响应格式

文字转语音接口直接返回音频文件的二进制流,而非 JSON 响应。请根据 response_format 参数指定的格式保存文件。

注意事项

注意

  • 语音转文字的音频文件大小上限为 25 MB
  • 文字转语音的文本长度上限为 4096 字符
  • 建议使用 tts-1-hd 模型以获得更高质量的语音

Star API - 统一的大模型接口网关