-
Notifications
You must be signed in to change notification settings - Fork 46
/
app.py
60 lines (42 loc) · 1.62 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
import os
import io
import base64
import json
from flask import Flask, request , make_response, Response, render_template
from flask_cors import CORS,cross_origin
import pyaudio
import numpy
# from src import synthesize as syn
# Initialize the Flask application
app = Flask(__name__)
## for allowing cors origin
cors = CORS(app, allow_headers='Content-Type', CORS_SEND_WILDCARD=True)
# route http posts to this method
@app.route('/api/test' , methods=['POST','GET'])
@cross_origin(origins='*', send_wildcard=True)
def synthesize_speech_sound():
target_text = request.form.get('target_text')
target_speaker = request.form.get('target_speaker')
if target_text == '':
data = {'status' : 'No target text provided'}
return Response(json.dumps(data), status=401, mimetype='application/json')
if target_speaker == '':
data = {'status' : 'No target speaker provided'}
return Response(json.dumps(data), status=402, mimetype='application/json')
# output, RATE = syn.synthesized_voice(target_text, target_speaker)
output = 'ashgdasgdhasgdh'
def generate():
fwav = io.StringIO(output.tobytes())
data = fwav.read(1024)
while data:
yield data
data = fwav.read(1024)
return Response(generate(), mimetype="audio/mp3")
@app.route('/')
def index():
""" Audio streaming home page. """
return render_template('test_stream.html')
# start flask app
if __name__ == "__main__":
## Change debug to False when deployed to production
app.run(debug=True,host="localhost", port=5000)