Skip to content

Commit 8ca5e90

Browse files
committed
frontend updates
1 parent 36dc6f9 commit 8ca5e90

18 files changed

+85
-49
lines changed

Azure/correct_sound.wav

24 KB
Binary file not shown.

Azure/input_sound.wav

662 KB
Binary file not shown.

audio_samples/break.m4a

161 KB
Binary file not shown.

audio_samples/no_pause1.wav

368 KB
Binary file not shown.

audio_samples/pause.wav

592 KB
Binary file not shown.
-8 Bytes
Binary file not shown.
Binary file not shown.

reconnect_app/app.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ def feedback():
145145
else:
146146
threshold = len(correct_list)//2
147147

148-
path_to_save = os.path.join(app.root_path, "static/Sounds", "plots.png")
148+
path_to_save = "static/Sounds/plots" + secrets.token_hex(6) + ".png"
149149
path_to_user = os.path.join(app.root_path, speech.user_audio_location)
150150
print("user_path -> ", path_to_user)
151151
path_to_correct = os.path.join(app.root_path, speech.correct_audio_filename)
152152
print("correct_path -> ", path_to_correct)
153-
has_breaks = SoundComparison().compare_waves(path_to_user, path_to_correct, path_to_save)
153+
long_breaks = SoundComparison().compare_waves(path_to_user, path_to_correct, path_to_save)
154154
# return_breaks("D:/Haverford/LocalHack/speech_analysis/reconnect_app/static/Sounds/input_soundd99ec5ce7675.wav", "D:/Haverford/LocalHack/speech_analysis/reconnect_app/static/Sounds/correct_sound145255b4ec90.wav", path_to_save)
155-
return render_template('feedback.html', pic_path="static/Sounds/plots.png", threshold=threshold, correct_list=correct_list, user_list=user_list, wrong_correct=wrong_correct, wrong_user=wrong_user, title="Reconnect - Feedback")
155+
return render_template('feedback.html', pic_path=path_to_save, threshold=threshold, correct_list=correct_list, user_list=user_list, wrong_correct=wrong_correct, wrong_user=wrong_user, title="Reconnect - Feedback")
156156

157157
@app.route("/restart")
158158
def restart():

reconnect_app/get_breaks.py

+41-33
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77

88
class SoundComparison:
99

10-
def compare_waves(self, speaker_sound, correct_sound, location_to_save):
10+
def __init__(self):
11+
self.result = {"too_little_breaks": False, "too_many_breaks": False,
12+
"short_breaks": [], "long_breaks": [],
13+
"short_pronunciation": [], "long_pronunciation": []}
14+
15+
def compare_waves(self, speaker_sound, correct_sound, location):
1116
speaker_rate, pre_speaker_data = scipy.io.wavfile.read(speaker_sound)
1217
correct_rate, correct_data = scipy.io.wavfile.read(correct_sound)
1318
speaker_data = self.stereo_to_mono(pre_speaker_data)
@@ -24,14 +29,14 @@ def compare_waves(self, speaker_sound, correct_sound, location_to_save):
2429
speaker_time = np.arange(0, len(speaker_data), 1) / speaker_rate
2530
correct_time = np.arange(0, len(correct_data), 1) / correct_rate
2631

27-
if self.check_for_long_breaks(speaker_data, speaker_rate) is not None:
28-
self.plot_graphs(correct_time, correct_data, speaker_time, speaker_data, "#5cb85c", location_to_save)
29-
return False
30-
self.plot_graphs(correct_time, correct_data, speaker_time, speaker_data, "#5cb85c", location_to_save)
31-
return self.check_sensibility_of_breaks(speaker_silence, correct_silence)
32-
# if self.check_for_amplitude_inconsistencies(speaker_data, speaker_rate, correct_data, correct_rate) is not None:
33-
# return False
34-
# return True
32+
self.check_sensibility_of_breaks(speaker_silence, correct_silence)
33+
long_breaks = self.result["long_breaks"]
34+
if(len(long_breaks)==0):
35+
self.plot_graphs(correct_time, correct_data, speaker_time, speaker_data, "#5cb85c", location)
36+
else:
37+
self.plot_graphs(correct_time, correct_data, speaker_time, speaker_data, "#f0ad4e", location)
38+
print(long_breaks)
39+
return long_breaks
3540

3641
def plot_graphs(self, correct_time, correct_data, speaker_time, speaker_data, color, location):
3742
# plot amplitude (or loudness) over time
@@ -83,8 +88,10 @@ def find_audio_chunk_breaks(self, audio_data, rate, silence_amplitude):
8388
def check_sensibility_of_breaks(self, speaker_breaks, correct_breaks):
8489
#last_time_difference is used to track the interval between gaps so that past differences would not stack up
8590
last_time_difference = 0
86-
if len(speaker_breaks) != len(correct_breaks):
87-
return False
91+
if len(speaker_breaks) > len(correct_breaks):
92+
self.result["too_many_breaks"] = True
93+
elif len(speaker_breaks) < len(correct_breaks):
94+
self.result["too_little_breaks"] = False
8895
else:
8996
for i in range(len(speaker_breaks)):
9097
speaker_start = speaker_breaks[i][0]
@@ -93,12 +100,17 @@ def check_sensibility_of_breaks(self, speaker_breaks, correct_breaks):
93100
correct_start = correct_breaks[i][0]
94101
correct_end = correct_breaks[i][1]
95102
correct_break_time = correct_end - correct_start
96-
if abs(speaker_break_time - correct_break_time) > 0.30:
97-
return False
98-
if abs(speaker_start - correct_start) > (last_time_difference + 0.2):
99-
return False
103+
if (speaker_end - speaker_start) > 2.2:
104+
self.result["long_breaks"].append(speaker_breaks[i])
105+
elif (speaker_break_time - correct_break_time) > 0.30:
106+
self.result["long_breaks"].append(speaker_breaks[i])
107+
elif (correct_break_time - speaker_break_time) > 0.30:
108+
self.result["short_breaks"].append(speaker_breaks[i])
109+
if (speaker_start - correct_start) > (last_time_difference + 0.5):
110+
self.result["long_pronunciation"].append((speaker_breaks[i-1][1], speaker_breaks[i][0]))
111+
elif (correct_start - speaker_start) > (last_time_difference + 0.5):
112+
self.result["short_pronunciation"].append((speaker_breaks[i-1][1], speaker_breaks[i][0]))
100113
last_time_difference = abs(correct_end - speaker_end)
101-
return True
102114

103115
def remove_audio_wave_silence(self, audio_data, rate, min=None):
104116
start_counter = 0
@@ -114,18 +126,18 @@ def calculate_silent_amplitude(self, audio_data, rate, min=None):
114126
end = int(rate/3)
115127
return max(max(audio_data[-end:]), 0.15) if min is None else 0.1
116128

117-
def check_for_long_breaks(self, audio_data, rate):
118-
counter = 0
119-
duration = 0
120-
while counter < len(audio_data):
121-
if audio_data[counter] < self.calculate_silent_amplitude(audio_data, rate):
122-
duration += 1
123-
if duration > (2.2 * rate):
124-
return counter / rate
125-
else:
126-
duration = 0
127-
counter += 1
128-
return None
129+
# def check_for_long_breaks(self, audio_data, rate):
130+
# counter = 0
131+
# duration = 0
132+
# while counter < len(audio_data):
133+
# if audio_data[counter] < self.calculate_silent_amplitude(audio_data, rate):
134+
# duration += 1
135+
# if duration > (2.2 * rate):
136+
# return counter / rate
137+
# else:
138+
# duration = 0
139+
# counter += 1
140+
# return None
129141

130142
# def check_for_amplitude_inconsistencies(self, audio_data1, rate1, audio_data2, rate2):
131143
# chunk_audio1 = self.convert_audio_data_to_chunk_audio_data(audio_data1, rate1)
@@ -145,9 +157,6 @@ def convert_audio_data_to_chunk_audio_data(self, audio_data, rate):
145157
chunk_audio_data[i] = chunk_audio_data[i] / (int(rate) / 10)
146158
return chunk_audio_data, int(rate/10)
147159

148-
def return_breaks(correct_loc, user_loc, location_to_save):
149-
print(SoundComparison().compare_waves(user_loc, correct_loc, location_to_save))
150-
151160
if __name__ == "__main__":
152161
# web_file="C:\Users\Samuel\PycharmProjects\speech_analysis\wave_comparison"
153162
#
@@ -173,5 +182,4 @@ def return_breaks(correct_loc, user_loc, location_to_save):
173182
# string += str(abs(happy[i] / max))
174183
# string += "|"
175184
# print(happy[10400:15000])
176-
177-
print(SoundComparison().compare_waves("D:/Haverford/LocalHack/speech_analysis/reconnect_app/static/Sounds/input_soundd99ec5ce7675.wav", "D:/Haverford/LocalHack/speech_analysis/reconnect_app/static/Sounds/correct_sound145255b4ec90.wav", "plots.png"))
185+
print(SoundComparison().compare_waves("D:/Haverford/LocalHack/speech_analysis/audio_samples/no_pause1.wav", "D:/Haverford/LocalHack/speech_analysis/reconnect_app/static/Sounds/correct_sound09d546aba5a4.wav", "plots.png"))

reconnect_app/plots.png

-63.5 KB
Binary file not shown.

reconnect_app/site.db

4 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading
Loading

reconnect_app/templates/feedback.html

+19
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,25 @@ <h5> Nice try! </h5>
7373
<hr>
7474
<strong><p class="lead"><span class="badge badge-info mr-2">2</span>Pacing</p></strong>
7575
<img src="{{ pic_path }}" />
76+
<div class="row pl-4">
77+
<div class="col">
78+
{% if long_breaks|length == 0 %}
79+
<div class="bd-callout bd-callout-success">
80+
<h5> Great job! </h5>
81+
<p>Congratulations! You pronounced the words with correct pace and you spoke naturally without significant breaks!</p>
82+
</div>
83+
{% else %}
84+
<div class="bd-callout bd-callout-warning">
85+
<h5> Nice try! </h5>
86+
<p>Your speeking was good, however, you made some significant breaks while pronoucing the sentence. Here are the times of your breaks:</p>
87+
<ol>
88+
{% for break in long_breaks %}
89+
<li>{{ break }}</li>
90+
{% endfor %}
91+
</ol>
92+
<p> Prectice makes perfect! Try decreasing the breaks between the words.</p>
93+
</div>
94+
{% endif %}
7695
<div class="row ">
7796
<div class="col text-center">
7897
<a href="{{ url_for('restart') }}" class="btn btn-info">Try again!</a>

wave_comparison/main.py

+22-13
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,30 @@ def compare_waves(self, speaker_sound, correct_sound):
2828
correct_silence = self.find_audio_chunk_breaks(correct_data, correct_rate, correct_data_silence)
2929

3030

31-
# plot amplitude (or loudness) over time
32-
# speaker_time = np.arange(0, len(speaker_data), 1) / speaker_rate
33-
# correct_time = np.arange(0, len(correct_data), 1) / correct_rate
34-
# plt.figure(1)
35-
# plt.subplot(211)
36-
# plt.plot(speaker_time, speaker_data, linewidth=0.1, alpha=1, color='#000000')
37-
# plt.xlabel('Time (s)')
38-
# plt.ylabel('Amplitude')
39-
# plt.subplot(212)
40-
# plt.plot(correct_time, correct_data, linewidth=0.1, alpha=1, color='#000000')
41-
# plt.show()
4231
self.check_sensibility_of_breaks(speaker_silence, correct_silence)
4332
return self.result
4433

34+
def plot_graphs(self, correct_time, correct_data, speaker_time, speaker_data, color, location):
35+
# plot amplitude (or loudness) over time
36+
37+
plt.subplot(211)
38+
plt.plot(correct_time, correct_data, linewidth=0.1, alpha=1, color=color)
39+
plt.xlabel('Time (s)')
40+
plt.ylabel('Amplitude')
41+
plt.title('Correct sound amplitude')
42+
43+
plt.figure(1)
44+
45+
plt.subplot(212)
46+
plt.plot(speaker_time, speaker_data, linewidth=0.1, alpha=1, color=color)
47+
plt.xlabel('Time (s)')
48+
plt.ylabel('Amplitude')
49+
plt.title("Your recording's amplitude")
50+
51+
plt.subplots_adjust(hspace=0.7)
52+
plt.savefig(location)
53+
# plt.show()
54+
4555
def stereo_to_mono(self, audio_data):
4656
audio_data = audio_data.astype(float)
4757
return audio_data.sum(axis=1)
@@ -165,5 +175,4 @@ def convert_audio_data_to_chunk_audio_data(self, audio_data, rate):
165175
# string += str(abs(happy[i] / max))
166176
# string += "|"
167177
# print(happy[10400:15000])
168-
print(SoundComparison().compare_waves("C:/Users/Samuel/PycharmProjects/speech_analysis/wave_comparison/input_sound.wav", "C:/Users/Samuel/PycharmProjects/speech_analysis/wave_comparison/correct_sound.wav"))
169-
178+
print(SoundComparison().compare_waves("D:/Haverford/LocalHack/speech_analysis/audio_samples/no_pause1.wav", "D:/Haverford/LocalHack/speech_analysis/reconnect_app/static/Sounds/correct_sound09d546aba5a4.wav"))

0 commit comments

Comments
 (0)