Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -55,6 +55,7 @@ def auto_reset_state():
|
|
55 |
time.sleep(2)
|
56 |
return None, "" # Reset the state and clear input text
|
57 |
|
|
|
58 |
# Function to process audio input and transcribe it
|
59 |
def transcribe_function(stream, new_chunk):
|
60 |
try:
|
@@ -72,20 +73,30 @@ def transcribe_function(stream, new_chunk):
|
|
72 |
if max_abs_y > 0:
|
73 |
y = y / max_abs_y
|
74 |
|
75 |
-
#
|
76 |
-
if stream is
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
-
#
|
82 |
-
result = pipe_asr({"array": stream, "sampling_rate": sr}, return_timestamps=False)
|
83 |
-
full_text = result.get("text", "")
|
84 |
|
85 |
-
# Start a thread to reset the state after 10 seconds
|
86 |
-
threading.Thread(target=auto_reset_state).start()
|
87 |
|
88 |
-
return stream, full_text, full_text
|
89 |
|
90 |
# Function to generate a full-text search query for Neo4j
|
91 |
#def generate_full_text_query(input: str) -> str:
|
|
|
55 |
time.sleep(2)
|
56 |
return None, "" # Reset the state and clear input text
|
57 |
|
58 |
+
|
59 |
# Function to process audio input and transcribe it
|
60 |
def transcribe_function(stream, new_chunk):
|
61 |
try:
|
|
|
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 |
|
101 |
# Function to generate a full-text search query for Neo4j
|
102 |
#def generate_full_text_query(input: str) -> str:
|