Working with OpenAI API and below is my simple code, but getting deprecation warning for 'steam_to_file' method.
Code -
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)
IDE - Visual Studio code
Warning as below -
** DeprecationWarning: Due to a bug, this method doesn't actually stream the response content, .with_streaming_response.method()
should be used instead
response.stream_to_file("song.mp3")**
Can anyone please help?
I tried to check through different forums but could not find error related to stream_to_file.
I am using Python 3.12