我在使用 openai 将文本转换为音频时,总是遇到这个错误:AttributeError: ‘HttpxBinaryResponseContent’ 对象没有属性 ‘with_streaming_response’。我尝试过使用 stream_to_field()
函数,但它也不起作用。
def audio(prompt):
speech_file_path=Path('C:\\Users\\beni7\\Downloads\\proyectos_programacion\\proyecto_shorts\\audio').parent / "speech.mp3"
response = openai.audio.speech.create(
model="tts-1",
voice="alloy",
input=prompt
)
response.with_streaming_response.method(speech_file_path)
回答:
.with_streaming_response 是 speech 上的一个方法。你可以尝试以下方法:
def audio(prompt):
speech_file_path="<file path>"
with client.audio.speech.with_streaming_response.create(
model="tts-1",
voice="alloy",
input=prompt,
) as response:
response.stream_to_file(speech_file_path)