Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -43,10 +43,13 @@ def analyze_voice_emotion(audio):
|
|
43 |
if y.dtype != 'float32':
|
44 |
y = y.astype('float32')
|
45 |
|
46 |
-
# Calculate features
|
47 |
pitch = float(librosa.feature.spectral_centroid(y=y, sr=sr).mean())
|
48 |
intensity = float(librosa.feature.rms(y=y).mean())
|
49 |
tempo, _ = librosa.beat.beat_track(y=y, sr=sr)
|
|
|
|
|
|
|
50 |
|
51 |
# Determine emotion based on features
|
52 |
if pitch < 150 and intensity < 0.02:
|
@@ -58,7 +61,10 @@ def analyze_voice_emotion(audio):
|
|
58 |
else:
|
59 |
emotion = "anxiety"
|
60 |
|
61 |
-
|
|
|
|
|
|
|
62 |
except Exception as e:
|
63 |
return f"Error analyzing audio: {str(e)}"
|
64 |
|
|
|
43 |
if y.dtype != 'float32':
|
44 |
y = y.astype('float32')
|
45 |
|
46 |
+
# Calculate features and convert numpy values to Python scalars
|
47 |
pitch = float(librosa.feature.spectral_centroid(y=y, sr=sr).mean())
|
48 |
intensity = float(librosa.feature.rms(y=y).mean())
|
49 |
tempo, _ = librosa.beat.beat_track(y=y, sr=sr)
|
50 |
+
|
51 |
+
# Convert tempo to Python float to avoid numpy formatting issues
|
52 |
+
tempo = float(tempo)
|
53 |
|
54 |
# Determine emotion based on features
|
55 |
if pitch < 150 and intensity < 0.02:
|
|
|
61 |
else:
|
62 |
emotion = "anxiety"
|
63 |
|
64 |
+
# Format the output using Python floats instead of numpy values
|
65 |
+
return "Emotion: {}\nPitch: {:.2f}\nIntensity: {:.2f}\nTempo: {:.2f}".format(
|
66 |
+
emotion, pitch, intensity, tempo
|
67 |
+
)
|
68 |
except Exception as e:
|
69 |
return f"Error analyzing audio: {str(e)}"
|
70 |
|