-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.py
95 lines (71 loc) · 2.33 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from re import split
from flask import Flask,render_template,request
from flask_bootstrap import Bootstrap
import test
import videoTester
import voiceAnalyzer
import time
import pyaudio
import os
import wave
app = Flask(__name__)
Bootstrap(app)
@app.route('/')
def index():
return render_template("index.html")
@app.route('/home')
def inde():
return render_template("index.html")
@app.route('/qstn')
def phq():
return render_template("phq9.html",data="Anxiety and Depression Detection")
@app.route('/expression')
def expression():
p=videoTester.exp()
return render_template("face.html",data=p)
@app.route('/face')
def face():
return render_template("face.html",data = "Anxiety and Depression Detection")
@app.route('/voice')
def voice():
return render_template("voice.html",data = "Click on the Mic to Record")
@app.route('/voice_recording')
def voice_recording():
CHUNK = 1024
FORMAT = pyaudio.paInt16 #paInt8
CHANNELS = 2
RATE = 44100 #sample rate
RECORD_SECONDS = 4
WAVE_OUTPUT_FILENAME = "output10.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK) #buffer
#return render_template("voice.html", data = "Recording ....")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data) # 2 bytes(16 bits) per channel
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
return render_template("voice.html", data = "Done recording.")
@app.route('/voice_analyzer')
def voice_analyzeer():
res = voiceAnalyzer.alalyzer()
res2 = os.system('python test.py -f output10.wav > output.txt')
file = open("output.txt","r")
#gender = ["male","female"]
for line in file:
if "Result:" in line:
sound = line.split()
res2 = sound[1]
return render_template("voice.html",data = res)