Spaces:
Sleeping
Sleeping
dlaiu
commited on
Commit
·
e1503ef
1
Parent(s):
ea19a0e
try again
Browse files
app.py
CHANGED
@@ -3,20 +3,21 @@ import parselmouth
|
|
3 |
from parselmouth.praat import call
|
4 |
import numpy as np
|
5 |
|
6 |
-
# def greet(name):
|
7 |
-
# return "Hello " + name + "!!"
|
8 |
-
|
9 |
-
# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
10 |
-
# demo.launch()
|
11 |
-
|
12 |
-
|
13 |
def get_pitch(audio_data):
|
14 |
-
rate, data = audio_data
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
demo = gr.Interface(fn=get_pitch, inputs="audio", outputs="text")
|
21 |
demo.launch()
|
22 |
-
|
|
|
3 |
from parselmouth.praat import call
|
4 |
import numpy as np
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def get_pitch(audio_data):
|
7 |
+
rate, data = audio_data
|
8 |
+
if data.ndim > 1: # Check if the audio is stereo or multi-channel
|
9 |
+
data = np.mean(data, axis=1) # Convert to mono by averaging channels
|
10 |
+
|
11 |
+
# Convert data to float64 for compatibility with Parselmouth
|
12 |
+
data = data.astype('float64')
|
13 |
+
|
14 |
+
sound = parselmouth.Sound(values=data, sampling_frequency=rate)
|
15 |
+
try:
|
16 |
+
pitch = call(sound, "To Pitch", 0.0, 75, 500)
|
17 |
+
pitch_values = pitch.selected_array['frequency']
|
18 |
+
return "Pitch frequencies: " + str(pitch_values)
|
19 |
+
except Exception as e:
|
20 |
+
return "Error in pitch extraction: " + str(e)
|
21 |
|
22 |
demo = gr.Interface(fn=get_pitch, inputs="audio", outputs="text")
|
23 |
demo.launch()
|
|