Spaces:
Running
on
Zero
Running
on
Zero
add a fix to support Chrome browser
Browse files
app.py
CHANGED
|
@@ -27,6 +27,14 @@ def predict_dialect(audio):
|
|
| 27 |
# Process the audio input
|
| 28 |
if len(audio_array.shape) > 1:
|
| 29 |
audio_array = audio_array.mean(axis=1) # Convert stereo to mono
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
print(f"Processing audio: sample rate={sr}, shape={audio_array.shape}")
|
| 32 |
|
|
|
|
| 27 |
# Process the audio input
|
| 28 |
if len(audio_array.shape) > 1:
|
| 29 |
audio_array = audio_array.mean(axis=1) # Convert stereo to mono
|
| 30 |
+
|
| 31 |
+
# Convert audio to float32 if it's not already (fix for Chrome recording issue)
|
| 32 |
+
if audio_array.dtype != np.float32:
|
| 33 |
+
# Normalize to [-1, 1] range as expected by the model
|
| 34 |
+
if audio_array.dtype == np.int16:
|
| 35 |
+
audio_array = audio_array.astype(np.float32) / 32768.0
|
| 36 |
+
else:
|
| 37 |
+
audio_array = audio_array.astype(np.float32)
|
| 38 |
|
| 39 |
print(f"Processing audio: sample rate={sr}, shape={audio_array.shape}")
|
| 40 |
|