forked from sovaai/sova-asr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecoder_app.py
31 lines (24 loc) · 836 Bytes
/
decoder_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
import configparser
from decoder import TrieDecoder
from flask import Flask, request
import json
import numpy as np
config = configparser.ConfigParser()
config.read("config.ini", encoding="UTF-8")
lexicon = config["Wav2Letter"]["lexicon"]
tokens = config["Wav2Letter"]["tokens"]
lm_path = config["Wav2Letter"]["lm_path"]
beam_threshold = float(config["Wav2Letter"]["beam_threshold"])
decoder = TrieDecoder(lexicon, tokens, lm_path, beam_threshold)
app = Flask(__name__)
@app.route("/decode", methods=["POST"])
def decode():
data = request.json
outputs = np.array(data["outputs"])
result = decoder.decode(outputs, start_timestamp=data["start_timestamp"])
results = {
"text": result.text,
"score": result.score,
"words": result.words
}
return json.dumps(results, ensure_ascii=False)