1

我在我的项目中使用了算法语音到文本,没有 docker,我的项目运行良好,但是当我向我的项目添加 dockerfile 并撰写时,算法语音到文本停止工作,给我这个错误:

Traceback (most recent call last):
backend     |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2464, in __call__
backend     |     return self.wsgi_app(environ, start_response)
backend     |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2450, in wsgi_app
backend     |     response = self.handle_exception(e)
backend     |   File "/usr/local/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
backend     |     return cors_after_request(app.make_response(f(*args, **kwargs)))
backend     |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1867, in handle_exception
backend     |     reraise(exc_type, exc_value, tb)
backend     |   File "/usr/local/lib/python3.9/site-packages/flask/_compat.py", line 39, in reraise
backend     |     raise value
backend     |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2447, in wsgi_app
backend     |     response = self.full_dispatch_request()
backend     |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1952, in full_dispatch_request
backend     |     rv = self.handle_user_exception(e)
backend     |   File "/usr/local/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function
backend     |     return cors_after_request(app.make_response(f(*args, **kwargs)))
backend     |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1821, in handle_user_exception
backend     |     reraise(exc_type, exc_value, tb)
backend     |   File "/usr/local/lib/python3.9/site-packages/flask/_compat.py", line 39, in reraise
backend     |     raise value
backend     |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
backend     |     rv = self.dispatch_request()
backend     |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
backend     |     return self.view_functions[rule.endpoint](**req.view_args)
backend     |   File "/app/app.py", line 123, in testRealize
backend     |     speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
backend     |   File "/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/speech.py", line 802, in __init__
backend     |     self._impl = self._get_impl(impl.SpeechRecognizer, speech_config, audio_config, language, source_language_config, auto_detect_source_language_config)
backend     |   File "/usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/speech.py", line 864, in _get_impl
backend     |     return reco_type._from_config(speech_config._impl)
backend     | RuntimeError: Exception with an error code: 0x38 (SPXERR_AUDIO_SYS_LIBRARY_NOT_FOUND)
backend     | [CALL STACK BEGIN]
backend     | 
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1fab3d) [0x7f4916de0b3d]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1fe082) [0x7f4916de4082]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1fa526) [0x7f4916de0526]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1fa660) [0x7f4916de0660]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1fa6c1) [0x7f4916de06c1]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x10fc59) [0x7f4916cf5c59]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x10fc59) [0x7f4916cf5c59]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1d3f4e) [0x7f4916db9f4e]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1e2d82) [0x7f4916dc8d82]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1e1a08) [0x7f4916dc7a08]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1e1cf9) [0x7f4916dc7cf9]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x260ad7) [0x7f4916e46ad7]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(recognizer_create_speech_recognizer_from_config+0x109) [0x7f4916e482c2]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/_speech_py_impl.so(+0x10693a) [0x7f491771293a]
backend     | /usr/local/lib/python3.9/site-packages/azure/cognitiveservices/speech/_speech_py_impl.so(+0x8837c) [0x7f491769437c]
backend     | /usr/local/lib/libpython3.9.so.1.0(+0x176b70) [0x7f491a28db70]
backend     | /usr/local/lib/libpython3.9.so.1.0(_PyObject_MakeTpCall+0x7d) [0x7f491a25ffbd]
backend     | [CALL STACK END]

我使用算法的部分代码:

def testRealize():
    begin = datetime.now()

    speech_config = speechsdk.SpeechConfig(
        subscription="ab************************", region="westeurope")
    speech_config.speech_recognition_language = "pt-PT"

    global speech_recognizer
    speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)

    global all_results
    all_results = []

    print("Speak into your microphone.")
    # result = speech_recognizer.recognize_once_async().get()

    speech_recognizer.session_started.connect(
        lambda evt: print('SESSION STARTED: {}'.format(evt)))
    speech_recognizer.session_stopped.connect(
        lambda evt: print('\nSESSION STOPPED {}'.format(evt)))
    speech_recognizer.recognized.connect(handle_final_result)

    speech_recognizer.start_continuous_recognition()
    # print(result.text)

    # return jsonify({'begin' : begin , 'text' : result.text })
    return jsonify({'begin': begin})


@app.route("/stop", methods=["GET", "POST"])
def stop():
    end = datetime.now()

    speech_recognizer.stop_continuous_recognition_async()
    speech_recognizer.session_started.disconnect_all()
    speech_recognizer.recognized.disconnect_all()
    speech_recognizer.session_stopped.disconnect_all()
    # print(all_results)

    return jsonify({'end': end, 'text': all_results})

问题是,如果我不使用 docker,算法就会运行,但是当我使用时,会出现上面的这个错误。而且我不知道为什么我会遇到这个问题。我必须快速解决这个问题。你能帮我吗?

谢谢。

4

1 回答 1

0

就我而言,我不得不将一些文件从 python 包复制到程序执行路径中。

python包路径:...\Lib\site-packages\azure\cognitiveservices\speech\

文件:

Microsoft.CognitiveServices.Speech.core.dll
Microsoft.CognitiveServices.Speech.extension.audio.sys.dll
Microsoft.CognitiveServices.Speech.extension.codec.dll
Microsoft.CognitiveServices.Speech.extension.kws.dll
Microsoft.CognitiveServices.Speech.extension.lu.dll

希望能帮助你得到一些启发。

于 2021-10-28T00:41:52.020 回答