Pijush2023 commited on
Commit
fb3074d
·
verified ·
1 Parent(s): 2eda2b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -92,23 +92,17 @@ def generate_audio_elevenlabs(text):
92
  "use_speaker_boost": False
93
  }
94
  }
95
-
96
- try:
97
- response = requests.post(tts_url, headers=headers, json=data, stream=True)
98
- if response.ok:
99
- # Create a proper temporary file for saving the audio response
100
- with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
101
- for chunk in response.iter_content(chunk_size=1024):
102
- if chunk:
103
- f.write(chunk)
104
- audio_path = f.name # Get the path of the saved audio file
105
- logging.debug(f"Audio saved to {audio_path}")
106
- return audio_path # Ensure the path is to a valid audio file
107
- else:
108
- logging.error(f"Error generating audio: {response.text}")
109
- return None
110
- except Exception as e:
111
- logging.error(f"Exception in generating audio: {str(e)}")
112
  return None
113
 
114
 
 
92
  "use_speaker_boost": False
93
  }
94
  }
95
+ response = requests.post(tts_url, headers=headers, json=data, stream=True)
96
+ if response.ok:
97
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
98
+ for chunk in response.iter_content(chunk_size=1024):
99
+ if chunk:
100
+ f.write(chunk)
101
+ audio_path = f.name
102
+ logging.debug(f"Audio saved to {audio_path}")
103
+ return audio_path # Return audio path for automatic playback
104
+ else:
105
+ logging.error(f"Error generating audio: {response.text}")
 
 
 
 
 
 
106
  return None
107
 
108