-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path:
23 lines (19 loc) · 786 Bytes
/
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pyaudio
from openai import OpenAI
client = OpenAI()
# Replace this with the correct device index for hw:1,0 from the previous step
device_index = 1 # Example index, replace with the actual index
p = pyaudio.PyAudio()
stream = p.open(format=8,
channels=1,
rate=24_000,
output=True,
output_device_index=device_index) # Set the output device
with client.audio.speech.with_streaming_response.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_format="pcm"
) as response:
for chunk in response.iter_bytes(1024):
stream.write(chunk)