请注意,我们的使用政策要求您向最终用户明确披露他们听到的 TTS 语音是 AI 生成的,而不是人声。
speechfrom pathlib import Path
from openai import OpenAI
client = OpenAI()
speech_file_path = Path(__file__).parent / "speech.mp3"
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input="Today is a wonderful day to build something people love!"
)
response.stream_to_file(speech_file_path)tts-1 tts-1-hdalloy echo fable onyx nova shimmerfrom openai import OpenAI
client = OpenAI()
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input="Hello world! This is a streaming test.",
)
response.stream_to_file("output.mp3")