Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -204,19 +204,25 @@ def transcribe_audio(audio, sample_rate=None):
|
|
| 204 |
print(f"Audio array dtype: {audio_array.dtype}")
|
| 205 |
|
| 206 |
# Guard against invalid input
|
| 207 |
-
if audio_array is None
|
| 208 |
print("Empty audio data received")
|
| 209 |
return "Error: No audio data received"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
# Convert to numpy array if needed
|
| 212 |
if not isinstance(audio_array, np.ndarray):
|
| 213 |
print("Converting to numpy array")
|
| 214 |
audio_array = np.array(audio_array, dtype=np.float32)
|
| 215 |
|
| 216 |
-
# Normalize audio if needed
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
|
|
|
| 220 |
|
| 221 |
# Get temporary file
|
| 222 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
|
|
|
|
| 204 |
print(f"Audio array dtype: {audio_array.dtype}")
|
| 205 |
|
| 206 |
# Guard against invalid input
|
| 207 |
+
if audio_array is None:
|
| 208 |
print("Empty audio data received")
|
| 209 |
return "Error: No audio data received"
|
| 210 |
+
|
| 211 |
+
if isinstance(audio_array, (list, np.ndarray)):
|
| 212 |
+
if len(audio_array) == 0:
|
| 213 |
+
print("Empty audio array received")
|
| 214 |
+
return "Error: No audio data received"
|
| 215 |
|
| 216 |
# Convert to numpy array if needed
|
| 217 |
if not isinstance(audio_array, np.ndarray):
|
| 218 |
print("Converting to numpy array")
|
| 219 |
audio_array = np.array(audio_array, dtype=np.float32)
|
| 220 |
|
| 221 |
+
# Normalize audio if needed - fix for the ambiguous truth value error
|
| 222 |
+
max_val = np.max(np.abs(audio_array))
|
| 223 |
+
if max_val > 1.0:
|
| 224 |
+
print(f"Normalizing audio values from max {max_val} to [-1.0, 1.0] range")
|
| 225 |
+
audio_array = audio_array / max_val
|
| 226 |
|
| 227 |
# Get temporary file
|
| 228 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
|