can run speechtotext server

This commit is contained in:
2022-09-26 18:06:34 +02:00
parent 66ccc108dc
commit 50a2db610d
3 changed files with 84 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
import os
import uuid
from flask import Flask
from flask import jsonify
from flask import request
from flask_cors import CORS, cross_origin
from src.workers.SpeechToText import SpeechToText
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.route('/', methods=['POST'])
@cross_origin()
def post():
file_name = str(uuid.uuid4()) + ".wav"
with open(file_name, "wb") as vid:
vid.write(request.data)
speech_to_text = SpeechToText()
result = speech_to_text.to_text(file_name)
try:
os.remove(file_name)
except OSError:
print(OSError)
return jsonify(result)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000, debug=True)