Spaces:
Runtime error
Runtime error
Update app.py
Browse filesFix for Safari microphone
app.py
CHANGED
|
@@ -83,7 +83,13 @@ def transcribe_audio_online_streaming(file, language):
|
|
| 83 |
while recognizer.is_ready(s):
|
| 84 |
recognizer.decode_streams([s])
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
except Exception as e:
|
| 89 |
yield f"Error: {e}"
|
|
@@ -112,6 +118,8 @@ def transcribe_microphone_stream(audio_chunk, stream_state, language):
|
|
| 112 |
return "", None
|
| 113 |
|
| 114 |
sample_rate, waveform_np = audio_chunk
|
|
|
|
|
|
|
| 115 |
|
| 116 |
# Resample if needed
|
| 117 |
if sample_rate != 16000:
|
|
@@ -133,6 +141,11 @@ def transcribe_microphone_stream(audio_chunk, stream_state, language):
|
|
| 133 |
recognizer.decode_streams([stream_state])
|
| 134 |
|
| 135 |
current_text = recognizer.get_result(stream_state)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
return current_text, stream_state
|
| 138 |
|
|
|
|
| 83 |
while recognizer.is_ready(s):
|
| 84 |
recognizer.decode_streams([s])
|
| 85 |
|
| 86 |
+
current_text = recognizer.get_result(s)
|
| 87 |
+
if isinstance(current_text, (list, np.ndarray)):
|
| 88 |
+
current_text = " ".join(map(str, current_text))
|
| 89 |
+
elif isinstance(current_text, bytes):
|
| 90 |
+
current_text = current_text.decode("utf-8", errors="ignore")
|
| 91 |
+
|
| 92 |
+
yield current_text
|
| 93 |
|
| 94 |
except Exception as e:
|
| 95 |
yield f"Error: {e}"
|
|
|
|
| 118 |
return "", None
|
| 119 |
|
| 120 |
sample_rate, waveform_np = audio_chunk
|
| 121 |
+
if len(waveform_np.shape) > 1:
|
| 122 |
+
waveform_np = waveform_np.mean(axis=1)
|
| 123 |
|
| 124 |
# Resample if needed
|
| 125 |
if sample_rate != 16000:
|
|
|
|
| 141 |
recognizer.decode_streams([stream_state])
|
| 142 |
|
| 143 |
current_text = recognizer.get_result(stream_state)
|
| 144 |
+
|
| 145 |
+
if isinstance(current_text, (list, np.ndarray)):
|
| 146 |
+
current_text = " ".join(map(str, current_text))
|
| 147 |
+
elif isinstance(current_text, bytes):
|
| 148 |
+
current_text = current_text.decode("utf-8", errors="ignore")
|
| 149 |
|
| 150 |
return current_text, stream_state
|
| 151 |
|