-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·63 lines (44 loc) · 1.27 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
from threading import Thread
from flask import Flask
from flask import request
from flask import send_file
import json
import os
# For Deepspeech
from deepspeech import Model
import wave
import numpy as np
# Server Config
IP_ADRESS = '0.0.0.0'
PORT = 8082
# Deepspeech Config
MODEL_FILENAME = '/app/model/deepspeech.tflite'
SCORER_FILENAME = '/app/model/deepspeech.scorer'
FILENAME = 'temp.wav'
# Define app as Flask-Server-Class
app = Flask(__name__)
# Deepspeech
ds = Model(MODEL_FILENAME)
ds.enableExternalScorer(SCORER_FILENAME)
# Start Deepspeech
def STT_Deepspeech(fname):
data = wave.open(fname, 'rb')
frames = data.readframes(data.getnframes())
audio = np.frombuffer(frames, np.int16)
return ds.stt(audio)
# request function over http://IP_ADRESS:PORT/stt
@app.route('/stt', methods=['POST', 'OPTIONS'])
def main():
try:
#get wav-file for stt
data = request.get_data()
with open(FILENAME,'wb') as f:
f.write(data)
res = STT_Deepspeech(FILENAME)
os.remove(FILENAME)
return { "STATUS":1, "DEEPSPEECH": res}
except:
return { "STATUS":-1, "DEEPSPEECH": ""}
# main function
if __name__ == '__main__':
app.run(host=IP_ADRESS, port=PORT, debug=True)