语音转文字 (Whisper) 和文字转语音 (TTS) 服务。
with open("audio.mp3", "rb") as f:
transcript = client.audio.transcriptions.create(
model="whisper-v3",
file=f,
language="zh"
)
print(transcript.text)
mp3, mp4, mpeg, mpga, m4a, wav, webm
最大文件大小: 25 MB
with open("chinese_audio.mp3", "rb") as f:
result = client.audio.translations.create(
model="whisper-v3",
file=f
)
print(result.text) # 英文翻译结果
response = client.audio.speech.create(
model="tts-1-hd",
voice="alloy",
input="你好,欢迎使用 BufferAPI!"
)
response.stream_to_file("output.mp3")
| 声音 | 风格 |
|---|---|
alloy | 中性,平衡 |
echo | 男声,深沉 |
fable | 英式,生动 |
onyx | 男声,低沉 |
nova | 女声,温暖 |
shimmer | 女声,柔和 |