Pijush2023 commited on
Commit
a54b7bc
·
verified ·
1 Parent(s): 164b9f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -21
app.py CHANGED
@@ -73,28 +73,20 @@ def transcribe_function(stream, new_chunk):
73
  if max_abs_y > 0:
74
  y = y / max_abs_y
75
 
76
- # Concatenate the new chunk to the existing stream if available
77
- stream = y if stream is None else np.concatenate([stream, y])
78
-
79
- # Check if the stream is at least 7 seconds long
80
- duration = len(stream) / sr
81
- if duration >= 7:
82
- # Process the audio data for transcription
83
- result = pipe_asr({"array": stream, "sampling_rate": sr}, return_timestamps=False)
84
- full_text = result.get("text", "")
85
- print(f"Transcription: {full_text}")
86
-
87
- # Retrieve hybrid response using Neo4j and other methods
88
- response_text = retriever(full_text)
89
- print(f"Response: {response_text}")
90
 
91
- # Generate audio from the response text
92
- audio_path = generate_audio_elevenlabs(response_text)
 
93
 
94
- # Reset the stream for the next chunk and return the generated audio
95
- return None, audio_path, full_text # Clear the stream after processing
96
 
97
- return stream, None, "" # Continue streaming until 7 seconds is reached
98
 
99
 
100
 
@@ -226,9 +218,9 @@ def process_audio_query(audio_input):
226
  interface = gr.Interface(
227
  fn=process_audio_query,
228
  inputs=gr.Audio(sources="microphone", type="numpy",streaming=True),
229
- outputs=gr.Audio(type="filepath", autoplay=True),
230
  description="Ask questions via audio and receive audio responses.",
231
- allow_flagging="never" # Disables the Clear button
232
  )
233
 
234
  # Launch the Gradio app
 
73
  if max_abs_y > 0:
74
  y = y / max_abs_y
75
 
76
+ # Ensure stream is also at least 1-dimensional before concatenation
77
+ if stream is not None and len(stream) > 0:
78
+ stream = np.concatenate([stream, y])
79
+ else:
80
+ stream = y
 
 
 
 
 
 
 
 
 
81
 
82
+ # Process the audio data for transcription
83
+ result = pipe_asr({"array": stream, "sampling_rate": sr}, return_timestamps=False)
84
+ full_text = result.get("text", "")
85
 
86
+ # Start a thread to reset the state after 10 seconds
87
+ threading.Thread(target=auto_reset_state).start()
88
 
89
+ return stream, full_text, full_text
90
 
91
 
92
 
 
218
  interface = gr.Interface(
219
  fn=process_audio_query,
220
  inputs=gr.Audio(sources="microphone", type="numpy",streaming=True),
221
+ outputs=gr.Audio(type="filepath", autoplay=True,interactive=False),
222
  description="Ask questions via audio and receive audio responses.",
223
+ #allow_flagging="never" # Disables the Clear button
224
  )
225
 
226
  # Launch the Gradio app