-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
73 lines (51 loc) · 1.92 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
import traceback
from flask import Flask,render_template,request
from flask_cors import cross_origin
import pyttsx3
app=Flask(__name__)
def text_to_speech(text, gender):
voice_dict = {'Male': 0, 'Female': 1}
code = voice_dict[gender]
print("code", code)
engine = pyttsx3.init()
print("engine initialization")
# Setting up voice rate
engine.setProperty('rate', 125)
# Setting up volume level between 0 and 1
engine.setProperty('volume', 0.8)
# Change voices: 0 for male and 1 for female
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[code].id)
engine.say(text)
engine.runAndWait()
@app.route('/',methods=['GET','POST'])
def mainpage():
msg="Enter the text to Translate!"
return render_template('frontpage.html',msg=msg)
@app.route('/text_conversion',methods=['GET','POST'])
def text_conversion():
print("inside text_conversion")
try:
if request.method == 'POST':
text = request.form['speech']
gender = request.form['voices']
print("text", text)
print("gender", str(gender))
gender1=str(gender)
try:
text_to_speech(text, gender1)
msg="Voice Translation Successful!"
print("msg ",msg)
return render_template('frontpage.html', msg=msg)
except:
print("inside text to speech except")
traceback.print_exc()
msg="voice conv not succesful111111"
return render_template('frontpage.html', msg=msg)
except:
print("inside text conversion except")
traceback.print_exc()
msg="voice conv not succesful"
return render_template('frontpage.html', msg=msg)
if __name__ == "__main__":
app.run(port=8000, debug=True)