音频(Audio)
音频 API 提供语音合成和音频转写能力。
- 语音合成:将文本转换为音频
- 音频转写:将音频转换为文本
语音合成
将输入文本转换为语音文件。
请求接口
http
POST https://api.nexusmodels.cn/v1/audio/speech请求头
http
Authorization: Bearer YOUR_NEXUSMODELS_API_KEY
Content-Type: application/json请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 语音合成模型名称 |
input | string | 是 | 需要转换为语音的文本 |
voice | string | 是 | 声音名称,取值由模型决定 |
response_format | string | 否 | 输出格式,例如 mp3、wav |
speed | number | 否 | 播放速度,支持范围由模型决定 |
请求示例
bash
curl -sS -X POST \
'https://api.nexusmodels.cn/v1/audio/speech' \
-H 'Authorization: Bearer YOUR_NEXUSMODELS_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "YOUR_TTS_MODEL",
"input": "欢迎使用 NexusModels API。",
"voice": "alloy",
"response_format": "mp3"
}' \
--output nexusmodels-speech.mp3验证输出文件
bash
ls -lh nexusmodels-speech.mp3
file nexusmodels-speech.mp3音频转写
将音频文件转换为文本。
请求接口
http
POST https://api.nexusmodels.cn/v1/audio/transcriptions请求头
http
Authorization: Bearer YOUR_NEXUSMODELS_API_KEY
Content-Type: multipart/form-data使用 curl -F 时,不需要手动设置 Content-Type,curl 会自动生成包含 boundary 的请求头。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 音频转写模型名称 |
file | file | 是 | 需要转写的音频文件 |
language | string | 否 | 音频语言,例如 zh、en |
prompt | string | 否 | 用于辅助识别的上下文提示 |
response_format | string | 否 | 返回格式,例如 json、text |
temperature | number | 否 | 控制转写结果随机性 |
请求示例
bash
curl -sS -X POST \
'https://api.nexusmodels.cn/v1/audio/transcriptions' \
-H 'Authorization: Bearer YOUR_NEXUSMODELS_API_KEY' \
-F 'model=YOUR_TRANSCRIPTION_MODEL' \
-F 'file=@audio.mp3' \
-F 'language=zh' \
-F 'response_format=json'响应示例
json
{
"text": "欢迎使用 NexusModels API。"
}