Pijush2023 commited on
Commit
53094f9
·
verified ·
1 Parent(s): 9916325

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -17
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
- # Transcribe audio input to text
216
- sr, y = audio
217
-
218
- # Ensure that the audio is in float32 format
219
- y = y.astype(np.float32)
220
- y = y / np.max(np.abs(y)) # Normalize audio to range [-1.0, 1.0]
221
-
222
- # Process the audio data with Whisper ASR
223
- result = pipe_asr({"array": y, "sampling_rate": sr}, return_timestamps=False)
224
- question = result.get("text", "")
225
-
226
- # Get response using the transcribed question
227
- response = get_response(question)
228
-
229
- # Generate audio from the response
230
- audio_path = generate_audio_elevenlabs(response)
231
- return audio_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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