nikhildsst commited on
Commit
9e9a95b
·
verified ·
1 Parent(s): 72c2dd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
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
- return f"Emotion: {emotion}\nPitch: {pitch:.2f}\nIntensity: {intensity:.2f}\nTempo: {tempo:.2f}"
 
 
 
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