gpt4 book ai didi

python - 语音SDK拖拽错误: Exception with an error code: 0xe (SPXERR_MIC_NOT_AVAILABLE)

转载 作者:行者123 更新时间:2023-12-03 06:23:34 30 4
gpt4 key购买 nike

我有一个Python小脚本:

def listen(language):
speech_config.speech_recognition_language=language
audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
print("Speak into your microphone.")
speech_recognition_result = speech_recognizer.recognize_once_async().get()
if speech_recognition_result.reason == speechsdk.ResultReason.RecognizedSpeech:
print("Recognized: {}".format(speech_recognition_result.text))
return speech_recognition_result.text

此代码源自此处的快速入门 SpeechSDK 教程:https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started-speech-to-text?tabs=linux%2Cterminal&pivots=programming-language-python

它在我的 MacOS Ventura 13.0 检测语音下完美运行。然而,当我在运行 Ubuntu 22.10 的 Linux 机器上使用完全相同的硬件进行音频检测时尝试它,它会抛出以下错误:

    Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.10/tkinter/__init__.py", line 1921, in __call__
return self.func(*args)
File "/home/fabian/Schreibtisch/Chatbot/gui.py", line 184, in <lambda>
command=lambda: main(set_language,"doctor"),
File "/home/fabian/Schreibtisch/Chatbot/ada_dialog_functions.py", line 233, in main
gender_age=ask_age_gender(language,language_voice_id,language_country_id)
File "/home/fabian/Schreibtisch/Chatbot/ada_dialog_functions.py", line 188, in ask_age_gender
answer=listen(language_country_id)
File "/home/fabian/Schreibtisch/Chatbot/ada_dialog_functions.py", line 15, in listen
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
File "/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/speech.py", line 1004, in __init__
_call_hr_fn(
File "/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/interop.py", line 62, in _call_hr_fn
_raise_if_failed(hr)
File "/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/interop.py", line 55, in _raise_if_failed
__try_get_error(_spx_handle(hr))
File "/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/interop.py", line 50, in __try_get_error
raise RuntimeError(message)
RuntimeError: Exception with error code:
[CALL STACK BEGIN]

/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.extension.audio.sys.so(+0xe0f1) [0x7f53e240e0f1]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1c9cf8) [0x7f53e31c9cf8]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0xf4c35) [0x7f53e30f4c35]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x18251b) [0x7f53e318251b]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0xe7ad3) [0x7f53e30e7ad3]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1c9cf8) [0x7f53e31c9cf8]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0xf4c35) [0x7f53e30f4c35]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x180101) [0x7f53e3180101]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x18334f) [0x7f53e318334f]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1309e7) [0x7f53e31309e7]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1309e7) [0x7f53e31309e7]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x15aeb1) [0x7f53e315aeb1]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x134d3d) [0x7f53e3134d3d]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1dc61d) [0x7f53e31dc61d]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x130815) [0x7f53e3130815]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1f87f6) [0x7f53e31f87f6]
/home/fabian/.local/lib/python3.10/site-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(recognizer_create_speech_recognizer_from_config+0xf2) [0x7f53e30d121b]
[CALL STACK END]

Exception with an error code: 0xe (SPXERR_MIC_NOT_AVAILABLE)

我尝试使用 device_name= "hw:CARD=U0x4b40x306,DEV=0 更改麦克风,但这也不起作用。此错误的大多数解决方案都没有提及我的操作系统组合和语言,因此并不真正适用。

最佳答案

我在我的环境中进行了尝试并得到了以下结果:

最初,当我在 Linux 机器上运行 python 脚本时,我遇到了同样的错误。

enter image description here

packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(recognizer_create_speech_recognizer_from_config+0xf2)[0x7fd4507d121b] [CALL STACK END]Exception with an error code: 0xe (SPXERR_MIC_NOT_AVAILABLE)

出现上述错误的原因是麦克风无法识别或语音识别系统未检测到。

在Linux中使用arecord -l检查您可以检查您正在使用的声卡。

在我的环境中,我在 Linux 计算机中安装了 pulseaudio,它对我有用。

命令:

sudo apt-get install alsa-base pulseaudio

控制台: enter image description here

安装pulseaudio后,现在我在我的环境中尝试使用相同的python脚本,它运行得很好。

代码:

import os
import azure.cognitiveservices.speech as speechsdk

def recognize_from_microphone():
# This example requires environment variables named "SPEECH_KEY" and "SPEECH_REGION"
speech_config = speechsdk.SpeechConfig(subscription=os.environ.get('SPEECH_KEY'), region=os.environ.get('SPEECH_REGION'))
speech_config.speech_recognition_language="en-US"

audio_config = speechsdk.audio.AudioConfig(use_default_microphone=True)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)

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

if speech_recognition_result.reason == speechsdk.ResultReason.RecognizedSpeech:
print("Recognized: {}".format(speech_recognition_result.text))
elif speech_recognition_result.reason == speechsdk.ResultReason.NoMatch:
print("No speech could be recognized: {}".format(speech_recognition_result.no_match_details))
elif speech_recognition_result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = speech_recognition_result.cancellation_details
print("Speech Recognition canceled: {}".format(cancellation_details.reason))
if cancellation_details.reason == speechsdk.CancellationReason.Error:
print("Error details: {}".format(cancellation_details.error_details))
print("Did you set the speech resource key and region values?")

recognize_from_microphone()

输出: enter image description here

引用:

  1. Sound Input device (microphone) not working
  2. pulseaudio - Headset microphone not working on Ubuntu 20.04

关于python - 语音SDK拖拽错误: Exception with an error code: 0xe (SPXERR_MIC_NOT_AVAILABLE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75720046/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com