There is a project on Flask. The python script contains pocketsphinx AudioFile .

Code

 from flask import Flask, render_template, json, request, jsonify, redirect app = Flask(__name__) import os from pocketsphinx import AudioFile, get_model_path, get_data_path from werkzeug.utils import secure_filename model_path = get_model_path() data_path = get_data_path() @app.route("/") def index(): return render_template('index.html') @app.route("/", methods=['POST']) def speech2text(): _file = request.form['file'] if _file: _file_name = _file.split('/')[-1] p = os.popen("sox static/load_files/audio/" + _file_name + " -r 16000 -c 1 static/load_files/audio/16khz_" +_file_name) config = { 'verbose': True, 'audio_file': os.path.join(data_path, "static/load_files/audio/16khz_"+ _file_name), 'buffer_size': 2048, 'no_search': False, 'full_utt': False, 'hmm': os.path.join(model_path, 'cmusphinx-ru-5.2'), 'lm': False, 'jsgf': os.path.join(model_path, 'grammar.jsgf'), 'dict': os.path.join(model_path, 'dictionary.dic'), } audio = AudioFile(**config) for phrase in audio: result_text = phrase return result_text else: return 'Увы, распознавание текста не удалось :(' if __name__ == "__main__": app.run(host='0.0.0.0', port=8080, ssl_context='adhoc') 

When you try to process the incoming file, an error flies

 [2019-02-21 12:20:00,148] ERROR in app: Exception on / [POST] Traceback (most recent call last): File "/home/mmamonova/speach2text-commands-sphinx/env/lib/python3.6/site-packa ges/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "/home/mmamonova/speach2text-commands-sphinx/env/lib/python3.6/site-packa ges/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/mmamonova/speach2text-commands-sphinx/env/lib/python3.6/site-packa ges/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/mmamonova/speach2text-commands-sphinx/env/lib/python3.6/site-packa ges/flask/_compat.py", line 35, in reraise raise value File "/home/mmamonova/speach2text-commands-sphinx/env/lib/python3.6/site-packa ges/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "/home/mmamonova/speach2text-commands-sphinx/env/lib/python3.6/site-packa ges/flask/app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "app.py", line 32, in speech2text audio = AudioFile(**config) File "/home/mmamonova/speach2text-commands-sphinx/env/lib/python3.6/site-packa ges/pocketsphinx/__init__.py", line 157, in __init__ signal.signal(signal.SIGINT, self.stop) File "/home/enosikova/anaconda3/lib/python3.6/signal.py", line 47, in signal handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler)) ValueError: signal only works in main thread 172.31.32.146 - - [21/Feb/2019 12:20:00] "POST / HTTP/1.1" 500 - 

By checking I found out that the error is due to the line

 audio = AudioFile(**conf) 

Tell me, how can I solve this problem? thank

  • Interesting ... and if so app.run(host='0.0.0.0', port=8080, ssl_context='adhoc', processes=True) ? - gil9red
  • @ gil9red, the same result - Maria Mamonova

0