Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -92,18 +92,26 @@ def generate_audio_elevenlabs(text):
|
|
92 |
"use_speaker_boost": False
|
93 |
}
|
94 |
}
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
return None
|
106 |
|
|
|
107 |
# Define the ASR model with Whisper
|
108 |
model_id = 'openai/whisper-large-v3'
|
109 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
|
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 |
+
|
115 |
# Define the ASR model with Whisper
|
116 |
model_id = 'openai/whisper-large-v3'
|
117 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|