jonathanagustin commited on
Commit
b60d60e
1 Parent(s): ef02dcd

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -44,22 +44,21 @@ def tts(
44
  openai.api_key = api_key
45
 
46
  try:
 
 
 
 
 
 
 
 
47
  # Save the audio content to a temporary file
48
  file_extension = f".{response_format}"
49
  with tempfile.NamedTemporaryFile(
50
  suffix=file_extension, delete=False, mode="wb"
51
  ) as temp_file:
52
  temp_file_path = temp_file.name
53
-
54
- # Use a context manager to handle the streaming response
55
- with openai.audio.speech.create(
56
- model=model,
57
- voice=voice,
58
- input=input_text,
59
- response_format=response_format,
60
- speed=speed,
61
- ) as response:
62
- response.stream_to_file(temp_file_path)
63
 
64
  except openai.OpenAIError as e:
65
  # Catch OpenAI exceptions
 
44
  openai.api_key = api_key
45
 
46
  try:
47
+ # Create the audio speech object
48
+ speech_file = openai.audio.speech.create(
49
+ model=model,
50
+ voice=voice,
51
+ input=input_text,
52
+ response_format=response_format,
53
+ speed=speed,
54
+ )
55
  # Save the audio content to a temporary file
56
  file_extension = f".{response_format}"
57
  with tempfile.NamedTemporaryFile(
58
  suffix=file_extension, delete=False, mode="wb"
59
  ) as temp_file:
60
  temp_file_path = temp_file.name
61
+ temp_file.write(speech_file.content)
 
 
 
 
 
 
 
 
 
62
 
63
  except openai.OpenAIError as e:
64
  # Catch OpenAI exceptions