birgermoell commited on
Commit
fecac47
1 Parent(s): e6a9b5c

Added graph

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -5,6 +5,8 @@ import numpy as np
5
  import soundfile as sf
6
  import io
7
  import librosa
 
 
8
 
9
  st.title("Syllables per Second Calculator")
10
  st.write("Upload an audio file to calculate the number of 'p', 't', and 'k' syllables per second.")
@@ -59,6 +61,25 @@ def get_syllables_per_second(audio_file):
59
  #print("the syllabels per second is: ", syllable_count / audio_duration)
60
  syllables_per_second = syllable_count / syllable_duration if syllable_duration > 0 else 0
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  return syllables_per_second
63
 
64
  uploaded_file = st.file_uploader("Choose an audio file", type=["wav"])
 
5
  import soundfile as sf
6
  import io
7
  import librosa
8
+ import matplotlib.pyplot as plt
9
+
10
 
11
  st.title("Syllables per Second Calculator")
12
  st.write("Upload an audio file to calculate the number of 'p', 't', and 'k' syllables per second.")
 
61
  #print("the syllabels per second is: ", syllable_count / audio_duration)
62
  syllables_per_second = syllable_count / syllable_duration if syllable_duration > 0 else 0
63
 
64
+ times = []
65
+ syllables_per_second_time = []
66
+ for i in range(len(syllable_offsets) - 1):
67
+ start = syllable_offsets[i]['start_offset'] * 0.02
68
+ end = syllable_offsets[i + 1]['end_offset'] * 0.02
69
+ duration = end - start
70
+ rate = 1 / duration if duration > 0 else 0
71
+ times.append(start)
72
+ syllables_per_second_time.append(rate)
73
+
74
+ plt.plot(times, syllables_per_second_time)
75
+ plt.xlabel('Time (s)')
76
+ plt.ylabel('Syllables per second')
77
+ # plt.show()
78
+ # save the figure
79
+ plt.savefig('syllables_per_second.png')
80
+ # show the image using streamlit
81
+ st.image('syllables_per_second.png')
82
+
83
  return syllables_per_second
84
 
85
  uploaded_file = st.file_uploader("Choose an audio file", type=["wav"])