jonathanagustin commited on
Commit
0bb3772
1 Parent(s): 4bac96b

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -44,20 +44,20 @@ def tts(
44
  openai.api_key = api_key
45
 
46
  try:
47
- response = openai.audio.speech.create(
 
48
  model=model,
49
  voice=voice,
50
  input=input_text,
51
  response_format=response_format,
52
  speed=speed,
53
- )
54
-
55
- # Save the audio content to a temporary file
56
- file_extension = f".{response_format}"
57
- with tempfile.NamedTemporaryFile(suffix=file_extension, delete=False) as temp_file:
58
- temp_file_path = temp_file.name
59
 
60
- with response.with_streaming_response():
 
 
 
61
  for chunk in response:
62
  temp_file.write(chunk)
63
 
 
44
  openai.api_key = api_key
45
 
46
  try:
47
+ # Use the context manager for streaming response
48
+ with openai.audio.speech.create(
49
  model=model,
50
  voice=voice,
51
  input=input_text,
52
  response_format=response_format,
53
  speed=speed,
54
+ stream=True, # Enable streaming
55
+ ) as response:
 
 
 
 
56
 
57
+ # Save the audio content to a temporary file
58
+ file_extension = f".{response_format}"
59
+ with tempfile.NamedTemporaryFile(suffix=file_extension, delete=False) as temp_file:
60
+ temp_file_path = temp_file.name
61
  for chunk in response:
62
  temp_file.write(chunk)
63