Skip to content

音频

提供 TTS(文本转语音)STT(语音转文本) 能力。

语音合成 POST

text
POST https://api.nassaapi.xyz/audio/speech

请求参数

参数类型必填说明
modelstringtts-1 / tts-1-hd
inputstring要合成的文本
voicestringalloy / echo / fable / onyx / nova / shimmer
response_formatstringmp3(默认) / opus / aac / flac
speednumber语速倍率 0.25–4.0,默认 1.0

示例请求

bash
curl -X POST "https://api.nassaapi.xyz/audio/speech" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxx" \
  -d '{
    "model": "tts-1",
    "input": "你好,欢迎使用NassaApi 中转站。",
    "voice": "alloy"
  }' \
  --output speech.mp3
python
from openai import OpenAI

client = OpenAI(
    api_key="sk-xxxx",
    base_url="https://api.nassaapi.xyz"
)

response = client.audio.speech.create(
    model="tts-1",
    voice="alloy",
    input="你好,欢迎使用NassaApi 中转站。"
)
response.stream_to_file("speech.mp3")
javascript
import OpenAI from 'openai';
import fs from 'fs';

const client = new OpenAI({
  apiKey: 'sk-xxxx',
  baseURL: 'https://api.nassaapi.xyz',
});

const response = await client.audio.speech.create({
  model: 'tts-1',
  voice: 'alloy',
  input: '你好,欢迎使用NassaApi 中转站。',
});

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

语音识别 POST

text
POST https://api.nassaapi.xyz/audio/transcriptions

请求参数

参数类型必填说明
modelstringwhisper-1
filefile音频文件(mp3 / wav / m4a 等)
languagestringISO 639-1 语言代码,如 zh
response_formatstringjson(默认) / text / srt / vtt
temperaturenumber采样温度,0–1

示例请求

bash
curl -X POST "https://api.nassaapi.xyz/audio/transcriptions" \
  -H "Authorization: Bearer sk-xxxx" \
  -F file="@audio.mp3" \
  -F model="whisper-1" \
  -F language="zh"
python
from openai import OpenAI

client = OpenAI(
    api_key="sk-xxxx",
    base_url="https://api.nassaapi.xyz"
)

with open("audio.mp3", "rb") as f:
    response = client.audio.transcriptions.create(
        model="whisper-1",
        file=f,
        language="zh"
    )
print(response.text)

响应

json
{
  "text": "你好,欢迎使用NassaApi 中转站。"
}

和谐、友善、互助、开心