Skip to content

Commit 27596d0

Browse files
committed
Front-end improvements
1 parent 66b42dd commit 27596d0

38 files changed

+336
-309
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/reconnect_env

reconnect_app/Azure/.vscode/.ropeproject/config.py

-114
This file was deleted.
-6 Bytes
Binary file not shown.
Binary file not shown.
-799 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

reconnect_app/Azure/correct_sound.wav

-205 KB
Binary file not shown.

reconnect_app/Azure/input_sound.wav

-3.31 MB
Binary file not shown.

reconnect_app/Azure/record_audio.py

-11
This file was deleted.

reconnect_app/Azure/run.py

-25
This file was deleted.

reconnect_app/Azure/text_to_speech.py

-30
This file was deleted.
-240 Bytes
Binary file not shown.
2.89 KB
Binary file not shown.
Binary file not shown.
936 Bytes
Binary file not shown.
Binary file not shown.
-450 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

reconnect_app/app.py

+95-36
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,121 @@
1-
from flask import Flask, render_template, url_for, redirect
1+
from flask import Flask, render_template, url_for, redirect, current_app
22
import azure.cognitiveservices.speech as speechsdk
3-
# #import text_to_speech as t_t_s
3+
from flask_sqlalchemy import SQLAlchemy
44
from text_to_speech import get_correct_sound
55
from text_to_speech import get_audio_length
6-
import sounddevice as sd
6+
#import sounddevice as sd
77
from scipy.io.wavfile import write
8+
from forms import CorrectSpeechForm, UserSpeechForm
9+
import os.path
10+
from os import path
11+
import time
12+
813
# from record_audio import record_audio
9-
# from speech_to_text import get_text_from_input
14+
from speech_to_text import get_text_from_input
1015
# from compare_text import *
16+
1117
app = Flask(__name__)
1218
speech_key, service_region = "c87da06e1dfe4dd3b6e58fa41ec19c95", "eastus"
1319
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
20+
app.config['SECRET_KEY'] = "4cf9c9881c554ef032f3a12c7f225dea"
21+
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
22+
db = SQLAlchemy(app)
23+
24+
class Speech(db.Model):
25+
id = db.Column(db.Integer, primary_key=True)
26+
correct_text = db.Column(db.String())
27+
correct_audio_filename = db.Column(db.String())
28+
# correct_audio = db.Column(None)
29+
# user_audio = db.Column(None)
30+
user_audio_location = db.Column(db.String())
31+
user_text = db.Column(db.String())
32+
def __repr__(self):
33+
return f"Speech('{self.id}', '{self.correct_text}', '{self.correct_audio_filename}')"
34+
1435
data = {
15-
"correct_text": "Hello! I love my cat and my dog",
16-
"path": "D:/Haverford/LocalHack/speech_analysis/reconnect_app/static/Sounds/",
17-
"correct_audio_filename": "correct_sound.wav"
36+
"correct_text": "This app doesn't work",
37+
"path": "D:/Haverford/LocalHack/speech_analysis/reconnect_app/static/CorrectSounds/",
38+
"correct_audio_filename": "correct_sound",
39+
"user_audio_filename" : "user_sound"
40+
1841
}
1942

43+
def get_file_name(filename):
44+
if filename[0]=="1":
45+
return filename[1:]
46+
else:
47+
return filename.split(".")[-1]+ "1" + filename.split(".")[-1]
48+
49+
def generate_user_text(user_audio_filename):
50+
new_file_name = str(time.time()) + data["user_audio_filename"] + str(time.time()) + ".wav"
51+
path_to_file = os.path.join(app.root_path, "static/Sounds", new_file_name)
52+
return get_text_from_input(path_to_file, speech_config)
53+
2054
def generate_correct_sound(correct_text):
21-
correct_text = correct_text
22-
path_to_file = data["path"] + data["correct_audio_filename"]
55+
new_file_name = data["correct_audio_filename"] + str(time.time()) + ".wav"
56+
print(new_file_name)
57+
path_to_file = os.path.join(app.root_path, "static/Sounds", new_file_name)
58+
if path.exists("static/Sounds/*"):
59+
os.remove("static/Sounds/*")
2360
correct_audio = get_correct_sound(path_to_file, correct_text, speech_config)
24-
return data["correct_audio_filename"]
61+
return "static/Sounds/" + new_file_name
2562

2663
@app.route("/")
27-
@app.route("/learn")
2864
def home():
29-
correct_sound_address = generate_correct_sound(data["correct_text"])
65+
return render_template('index.html', title="Reconnect - Main")
3066

31-
return render_template('index.html', correct_sound_address=correct_sound_address, cor_str=data["correct_text"])
67+
@app.route("/learn", methods=["GET", "POST"])
68+
def learn():
69+
correct_form = CorrectSpeechForm()
70+
if correct_form.submitc.data and correct_form.validate_on_submit():
71+
user_form = UserSpeechForm()
72+
print(correct_form.correct_text.data)
73+
correct_sound_address = generate_correct_sound(correct_form.correct_text.data)
74+
correct_audio = open(correct_sound_address)
75+
speech = Speech(correct_text=correct_form.correct_text.data, correct_audio_filename=correct_sound_address)
76+
print("from learn -> ", speech)
77+
db.session.add(speech)
78+
db.session.commit()
79+
return redirect(url_for('practice'))
3280

81+
return render_template('learn.html', correct_form=correct_form, title="Learn - Reconnect")
3382

83+
@app.route("/practice", methods=["GET", "POST"])
84+
def practice():
85+
user_form = UserSpeechForm()
86+
correct_form = CorrectSpeechForm()
87+
speech = Speech.query.order_by(-Speech.id).first()
88+
89+
print("we got to practice route")
90+
print(speech)
91+
#doesn't validate the form?? doesn't get into next lines
92+
if user_form.submitu.data and user_form.validate_on_submit():
93+
print("Got the sound!")
94+
speech.user_audio_location = user_form.user_speech.data.name
95+
speech.user_text = generate_user_text(user_form.user_speech.data.name)
96+
db.session.commit()
97+
return url_for('feedback', speech=speech)
98+
return render_template('practice.html', correct_text=speech.correct_text, correct_form=correct_form, user_form=user_form, correct_sound_address=str(speech.correct_audio_filename), title="Practice - Reconnect")
99+
100+
101+
102+
103+
def learn2():
104+
if speech:
105+
user_form = UserSpeechForm()
106+
if user_form.validate_on_submit():
107+
print("Got the sound!")
108+
user_text = generate_user_text(user_form.user_speech.data.name)
109+
speech.user_audio = user_form.user_speech
110+
speech.user_text = user_text
111+
db.session.commit()
112+
return render_template('learn.html', correct_form=correct_form, title="Learn - Reconnect", correct_text = correct_form.correct_text.data, speech=speech, correct_sound_address=correct_sound_address)
34113

35114

36115
@app.route("/feedback")
37-
def start():
38-
39-
#
40-
#correct_audio_filename = "/static/correct_sound.wav"
41-
#correct_text = data["correct_text"]
42-
#
43-
# correct_audio = get_correct_sound(correct_audio_filename, correct_text, speech_config)
44-
# correct_length = get_audio_length(correct_audio_filename)
45-
#
46-
# input_audio_filename = "input_sound.wav"
47-
# input_text = get_text_from_input(input_audio_filename, speech_config)
48-
#
49-
# differences = compare(correct_text, input_text)
50-
# difs_og = keys(differences)
51-
# difs_new = values(differences)
52-
#
53-
# spl_og = correct_text.split(" ")
54-
# spl_new = input_text.split(" ")
55-
# if(is_empty(differences)):
56-
# difs_og = None
57-
# difs_new = None
58-
# return render_template('index2.html', cor_str=data["correct_text"], input_text=input_text, difs_og=difs_og, difs_new=difs_new, spl_og=spl_og, spl_new=spl_new)
59-
return render_template('index2.html')
116+
def feedback():
117+
118+
return render_template('feedback.html')
60119

61120

62121
if __name__ == '__main__':

reconnect_app/correct_sound.wav

-96.7 KB
Binary file not shown.

reconnect_app/forms.py

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
from flask_wtf import FlaskForm
2-
from wtforms import StringField, PasswordField, SubmitField, BooleanField
2+
from wtforms import TextField, FileField, SubmitField
33
from wtforms.validators import DataRequired, Length, Email, EqualTo
44

55

6-
class Speech(FlaskForm):
7-
correct_next = StringField('Text',
8-
validators=[DataRequired(), Length(min=2, max=20)])
9-
email = StringField('Email',
10-
validators=[DataRequired(), Email()])
11-
password = PasswordField('Password', validators=[DataRequired()])
12-
confirm_password = PasswordField('Confirm Password',
13-
validators=[DataRequired(), EqualTo('password')])
14-
submit = SubmitField('Sign Up')
6+
class CorrectSpeechForm(FlaskForm):
7+
correct_text = TextField('Type in the sentence you want to practice today:', validators=[DataRequired()])
8+
submitc = SubmitField('Generate correct sound')
159

1610

17-
class LoginForm(FlaskForm):
18-
email = StringField('Email',
19-
validators=[DataRequired(), Email()])
20-
password = PasswordField('Password', validators=[DataRequired()])
21-
remember = BooleanField('Remember Me')
22-
submit = SubmitField('Login')
11+
class UserSpeechForm(FlaskForm):
12+
user_speech = FileField('Your recording', validators=[DataRequired()])
13+
submitu = SubmitField('Submit recording')

reconnect_app/site.db

8 KB
Binary file not shown.
File renamed without changes.
-113 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-205 KB
Binary file not shown.
File renamed without changes.

0 commit comments

Comments
 (0)