Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -275,22 +275,29 @@ def transcribe_function(stream, new_chunk):
|
|
275 |
print(f"Error chunk structure: {type(new_chunk)}, content: {new_chunk}")
|
276 |
return stream, "", None
|
277 |
|
|
|
|
|
|
|
|
|
278 |
y = y.astype(np.float32)
|
279 |
max_abs_y = np.max(np.abs(y))
|
280 |
if max_abs_y > 0:
|
281 |
y = y / max_abs_y
|
282 |
|
283 |
-
|
|
|
284 |
stream = np.concatenate([stream, y])
|
285 |
else:
|
286 |
stream = y
|
287 |
|
|
|
288 |
result = pipe_asr({"array": stream, "sampling_rate": sr}, return_timestamps=False)
|
289 |
full_text = result.get("text", "")
|
290 |
|
291 |
return stream, full_text, full_text
|
292 |
|
293 |
|
|
|
294 |
# Define the function to clear the state and input text
|
295 |
def clear_transcription_state():
|
296 |
return None, ""
|
|
|
275 |
print(f"Error chunk structure: {type(new_chunk)}, content: {new_chunk}")
|
276 |
return stream, "", None
|
277 |
|
278 |
+
# Ensure y is not empty and is at least 1-dimensional
|
279 |
+
if y is None or len(y) == 0:
|
280 |
+
return stream, "", None
|
281 |
+
|
282 |
y = y.astype(np.float32)
|
283 |
max_abs_y = np.max(np.abs(y))
|
284 |
if max_abs_y > 0:
|
285 |
y = y / max_abs_y
|
286 |
|
287 |
+
# Ensure stream is also at least 1-dimensional before concatenation
|
288 |
+
if stream is not None and len(stream) > 0:
|
289 |
stream = np.concatenate([stream, y])
|
290 |
else:
|
291 |
stream = y
|
292 |
|
293 |
+
# Process the audio data for transcription
|
294 |
result = pipe_asr({"array": stream, "sampling_rate": sr}, return_timestamps=False)
|
295 |
full_text = result.get("text", "")
|
296 |
|
297 |
return stream, full_text, full_text
|
298 |
|
299 |
|
300 |
+
|
301 |
# Define the function to clear the state and input text
|
302 |
def clear_transcription_state():
|
303 |
return None, ""
|