语音处理

语音转文字 (Whisper) 和文字转语音 (TTS) 服务。

语音转文字 (Whisper)

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)  # 英文翻译结果

文字转语音 (TTS)

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女声,柔和