Spaces:
Runtime error
Runtime error
Birger Moell
commited on
Commit
•
861fa20
1
Parent(s):
74eeb73
Updated offsets
Browse files
app.py
CHANGED
@@ -25,9 +25,19 @@ def get_syllables_per_second(audio_file):
|
|
25 |
transcription = processor.batch_decode(predicted_ids, output_char_offsets=True)
|
26 |
offsets = transcription['char_offsets']
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
return syllables_per_second
|
33 |
|
@@ -36,4 +46,4 @@ uploaded_file = st.file_uploader("Choose an audio file", type=["wav"])
|
|
36 |
if uploaded_file is not None:
|
37 |
with st.spinner("Processing the audio file..."):
|
38 |
result = get_syllables_per_second(uploaded_file)
|
39 |
-
st.write("Syllables per second: ", result)
|
|
|
25 |
transcription = processor.batch_decode(predicted_ids, output_char_offsets=True)
|
26 |
offsets = transcription['char_offsets']
|
27 |
|
28 |
+
# Find the start and end time offsets of the syllables
|
29 |
+
syllable_offsets = [item for item in offsets[0] if item['char'] in ['p', 't', 'k']]
|
30 |
+
|
31 |
+
if syllable_offsets: # if any syllable is found
|
32 |
+
first_syllable_offset = syllable_offsets[0]['start_offset'] / sample_rate
|
33 |
+
last_syllable_offset = syllable_offsets[-1]['end_offset'] / sample_rate
|
34 |
+
# Duration from the first to the last syllable
|
35 |
+
syllable_duration = last_syllable_offset - first_syllable_offset
|
36 |
+
else:
|
37 |
+
syllable_duration = 0
|
38 |
+
|
39 |
+
syllable_count = len(syllable_offsets)
|
40 |
+
syllables_per_second = syllable_count / syllable_duration if syllable_duration > 0 else 0
|
41 |
|
42 |
return syllables_per_second
|
43 |
|
|
|
46 |
if uploaded_file is not None:
|
47 |
with st.spinner("Processing the audio file..."):
|
48 |
result = get_syllables_per_second(uploaded_file)
|
49 |
+
st.write("Syllables per second: ", result)
|