Birger Moell commited on
Commit
861fa20
1 Parent(s): 74eeb73

Updated offsets

Browse files
Files changed (1) hide show
  1. app.py +14 -4
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
- audio_duration = len(audio_input) / sample_rate
29
- syllable_count = sum(1 for item in offsets[0] if item['char'] in ['p', 't', 'k'])
30
- syllables_per_second = syllable_count / audio_duration
 
 
 
 
 
 
 
 
 
 
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)