我正在尝试使用 Azure 认知服务和 Python 创建自定义唤醒词。我正在关注快速入门教程 -
我已经使用语音工作室生成了关键字模型,现在我正在尝试在 Python 中实现它。快速入门有 C# 示例,其中使用 CognitiveServices.Speech、CognitiveServices.Speech.Audio。.NET 具有实现关键字识别的 KeywordRecognizer 类。
在 Python 中,没有 KeywordRecognizer 类,但是有一个Recognizer,它有 start_keyword_recognition 方法。
最初我使用它如下 -
keywordModel = speechsdk.KeywordRecognitionModel("hello_raven.table")
#audioConfig = audiosdk.AudioConfig(use_default_microphone = True)
keywordRecognizer = speechsdk.Recognizer()
result = keywordRecognizer.start_keyword_recognition(keywordModel)
当我执行它时,出现以下错误 -
AttributeError:“识别器”对象没有属性“_impl”
当我提到speech.py时,它具有以下关键字识别实现-
def start_keyword_recognition(self, model: KeywordRecognitionModel):
"""
Synchronously initiates keyword recognition operation.
:param model: the keyword recognition model that specifies the keyword to be recognized.
"""
return self._impl.start_keyword_recognition(model._impl)
识别器类具有返回 _impl 的静态方法,但它使用 _from_config 方法,我无法在 Speech.py 中找到该方法。
- 我们可以直接使用识别器类和 start_keyword_recognition 方法吗?
- 如果没有,请向我提供有关如何实现它的任何指示。
如果需要更多详细信息,请告诉我。
@staticmethod
def _get_impl(reco_type, speech_config, audio_config):
if audio_config is not None:
_impl = reco_type._from_config(speech_config._impl, audio_config._impl)
else:
_impl = reco_type._from_config(speech_config._impl, None)
return _impl