使用 OpenAI API 及以下是我的简单代码,但收到“steam_to_file”方法的弃用警告。
代码 -
from openai import OpenAI
from pathlib import Path
client = OpenAI(
api_key=os.getenv("OPENAI_API_KEY"),
)
speech_file_path = Path(__file__).parent / "speech.mp3"
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input= '''I see skies of blue and clouds of white
The bright blessed days, the dark sacred nights
And I think to myself
What a wonderful world
'''
)
response.stream_to_file(speech_file_path)
Run Code Online (Sandbox Code Playgroud)
IDE——Visual Studio 代码
警告如下 -
** DeprecationWarning:由于错误,此方法实际上并不传输响应内容,.with_streaming_response.method()应使用 response.stream_to_file("song.mp3")**
有人可以帮忙吗?
我尝试检查不同的论坛,但找不到与stream_to_file相关的错误。
我正在使用Python 3.12