Spaces:
Sleeping
Sleeping
Update app.py
Browse filesFixed the issue on Audio
app.py
CHANGED
|
@@ -150,8 +150,14 @@ def analyze_audio(audio):
|
|
| 150 |
if audio_data is None or len(audio_data) == 0:
|
| 151 |
return "Invalid audio", "0%", "Unreadable audio", None
|
| 152 |
|
|
|
|
| 153 |
if len(audio_data.shape) > 1:
|
| 154 |
-
audio_data = np.mean(audio_data, axis=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
preds = pipe({"raw": audio_data, "sampling_rate": int(sample_rate)})
|
| 157 |
|
|
@@ -166,10 +172,12 @@ def analyze_audio(audio):
|
|
| 166 |
}
|
| 167 |
|
| 168 |
return f"{emoji_map.get(emotion,'🎤')} {emotion}", f"{top['score']*100:.1f}%", details, mood_type
|
|
|
|
| 169 |
except Exception as e:
|
| 170 |
return "❌ Error", "0%", f"Analysis failed: {str(e)}", None
|
| 171 |
|
| 172 |
|
|
|
|
| 173 |
############################################################
|
| 174 |
# 6. UI
|
| 175 |
############################################################
|
|
|
|
| 150 |
if audio_data is None or len(audio_data) == 0:
|
| 151 |
return "Invalid audio", "0%", "Unreadable audio", None
|
| 152 |
|
| 153 |
+
# Stereo -> mono
|
| 154 |
if len(audio_data.shape) > 1:
|
| 155 |
+
audio_data = np.mean(audio_data, axis=1)
|
| 156 |
+
|
| 157 |
+
# --- FIX: convert int16 to float32 ---
|
| 158 |
+
if audio_data.dtype != np.float32:
|
| 159 |
+
# normalize int16 audio to [-1.0, 1.0]
|
| 160 |
+
audio_data = audio_data.astype(np.float32) / 32768.0
|
| 161 |
|
| 162 |
preds = pipe({"raw": audio_data, "sampling_rate": int(sample_rate)})
|
| 163 |
|
|
|
|
| 172 |
}
|
| 173 |
|
| 174 |
return f"{emoji_map.get(emotion,'🎤')} {emotion}", f"{top['score']*100:.1f}%", details, mood_type
|
| 175 |
+
|
| 176 |
except Exception as e:
|
| 177 |
return "❌ Error", "0%", f"Analysis failed: {str(e)}", None
|
| 178 |
|
| 179 |
|
| 180 |
+
|
| 181 |
############################################################
|
| 182 |
# 6. UI
|
| 183 |
############################################################
|