Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -212,23 +212,37 @@ pipe_asr = pipeline(
|
|
212 |
|
213 |
# Function to handle voice input, generate response from Neo4j, and return audio output
|
214 |
def handle_voice_to_voice(audio):
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
|
233 |
|
234 |
# Define the Gradio interface
|
|
|
212 |
|
213 |
# Function to handle voice input, generate response from Neo4j, and return audio output
|
214 |
def handle_voice_to_voice(audio):
|
215 |
+
try:
|
216 |
+
# Transcribe audio input to text
|
217 |
+
sr, y = audio
|
218 |
+
y = y.astype(np.float32)
|
219 |
+
y = y / np.max(np.abs(y)) # Normalize audio to range [-1.0, 1.0]
|
220 |
+
|
221 |
+
logging.debug(f"Audio sample rate: {sr}")
|
222 |
+
logging.debug(f"Audio data: {y[:100]}") # Log first 100 samples for brevity
|
223 |
+
|
224 |
+
# Process the audio data with Whisper ASR
|
225 |
+
result = pipe_asr({"array": y, "sampling_rate": sr}, return_timestamps=False)
|
226 |
+
question = result.get("text", "")
|
227 |
+
|
228 |
+
logging.debug(f"Transcribed question: {question}")
|
229 |
+
|
230 |
+
if not question:
|
231 |
+
return "No transcription available, please try again."
|
232 |
+
|
233 |
+
# Get response using the transcribed question
|
234 |
+
response = get_response(question)
|
235 |
+
logging.debug(f"Response from Neo4j and GPT: {response}")
|
236 |
+
|
237 |
+
# Generate audio from the response
|
238 |
+
audio_path = generate_audio_elevenlabs(response)
|
239 |
+
logging.debug(f"Generated audio path: {audio_path}")
|
240 |
+
|
241 |
+
return audio_path
|
242 |
+
except Exception as e:
|
243 |
+
logging.error(f"Error in handle_voice_to_voice: {e}")
|
244 |
+
return "Error processing the audio, please try again."
|
245 |
+
|
246 |
|
247 |
|
248 |
# Define the Gradio interface
|