Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -442,6 +442,26 @@ base_audio_drive = "/data/audio"
|
|
442 |
|
443 |
#Normal Code with sample rate is 44100 Hz
|
444 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
445 |
def transcribe_function(stream, new_chunk):
|
446 |
try:
|
447 |
sr, y = new_chunk[0], new_chunk[1]
|
@@ -449,16 +469,29 @@ def transcribe_function(stream, new_chunk):
|
|
449 |
print(f"Error chunk structure: {type(new_chunk)}, content: {new_chunk}")
|
450 |
return stream, "", None
|
451 |
|
452 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
453 |
|
454 |
if stream is not None:
|
455 |
-
stream = np.concatenate([stream,
|
456 |
else:
|
457 |
-
stream =
|
458 |
|
|
|
459 |
result = pipe_asr({"array": stream, "sampling_rate": sr}, return_timestamps=False)
|
460 |
|
461 |
-
full_text = result.get("text","")
|
462 |
|
463 |
return stream, full_text, result
|
464 |
|
|
|
442 |
|
443 |
#Normal Code with sample rate is 44100 Hz
|
444 |
|
445 |
+
# def transcribe_function(stream, new_chunk):
|
446 |
+
# try:
|
447 |
+
# sr, y = new_chunk[0], new_chunk[1]
|
448 |
+
# except TypeError:
|
449 |
+
# print(f"Error chunk structure: {type(new_chunk)}, content: {new_chunk}")
|
450 |
+
# return stream, "", None
|
451 |
+
|
452 |
+
# y = y.astype(np.float32) / np.max(np.abs(y))
|
453 |
+
|
454 |
+
# if stream is not None:
|
455 |
+
# stream = np.concatenate([stream, y])
|
456 |
+
# else:
|
457 |
+
# stream = y
|
458 |
+
|
459 |
+
# result = pipe_asr({"array": stream, "sampling_rate": sr}, return_timestamps=False)
|
460 |
+
|
461 |
+
# full_text = result.get("text","")
|
462 |
+
|
463 |
+
# return stream, full_text, result
|
464 |
+
|
465 |
def transcribe_function(stream, new_chunk):
|
466 |
try:
|
467 |
sr, y = new_chunk[0], new_chunk[1]
|
|
|
469 |
print(f"Error chunk structure: {type(new_chunk)}, content: {new_chunk}")
|
470 |
return stream, "", None
|
471 |
|
472 |
+
# Check if the array is empty
|
473 |
+
if y.size == 0:
|
474 |
+
print("Received an empty audio chunk, skipping processing.")
|
475 |
+
return stream, "", None
|
476 |
+
|
477 |
+
y = y.astype(np.float32)
|
478 |
+
|
479 |
+
# Check if y is all zeros or contains no valid data
|
480 |
+
if np.max(np.abs(y)) == 0:
|
481 |
+
print("Audio chunk contains only zeros, skipping normalization.")
|
482 |
+
normalized_y = y
|
483 |
+
else:
|
484 |
+
normalized_y = y / np.max(np.abs(y))
|
485 |
|
486 |
if stream is not None:
|
487 |
+
stream = np.concatenate([stream, normalized_y])
|
488 |
else:
|
489 |
+
stream = normalized_y
|
490 |
|
491 |
+
# Placeholder for ASR pipeline; replace with actual pipeline
|
492 |
result = pipe_asr({"array": stream, "sampling_rate": sr}, return_timestamps=False)
|
493 |
|
494 |
+
full_text = result.get("text", "")
|
495 |
|
496 |
return stream, full_text, result
|
497 |
|