I got the output of OAI TTS to stream. Here’s an example:
url = "https://api.openai.com/v1/audio/speech"
headers = {
"Authorization": 'Bearer YOUR_API_KEY',
}
data = {
"model": model,
"input": input_text,
"voice": voice,
"response_format": "opus",
}
with requests.post(url, headers=headers, json=data, stream=True) as response:
if response.status_code == 200:
buffer = io.BytesIO()
for chunk in response.iter_content(chunk_size=4096):
buffer.write(chunk)