2

我正在尝试使用 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​​ 中找到该方法。

  1. 我们可以直接使用识别器类和 start_keyword_recognition 方法吗?
  2. 如果没有,请向我提供有关如何实现它的任何指示。

如果需要更多详细信息,请告诉我。

 @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
4

1 回答 1

0

Azure 团队已经上传了几乎所有案例的示例,我从那里得到了解决方案。

来自 Github 网站的代码片段 -

speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

# Creates an instance of a keyword recognition model. Update this to
# point to the location of your keyword recognition model.
model = speechsdk.KeywordRecognitionModel("YourKeywordRecognitionModelFile.table")

# The phrase your keyword recognition model triggers on.
keyword = "YourKeyword"

speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)

done = False

def stop_cb(evt):
    """callback that signals to stop continuous recognition upon receiving an event `evt`"""
..........
..........

# Start keyword recognition
speech_recognizer.start_keyword_recognition(model)
print('Say something starting with "{}" followed by whatever you want...'.format(keyword))
while not done:
    time.sleep(.5)

speech_recognizer.stop_keyword_recognition()

github站点的链接是-

Github Azure 示例

于 2020-09-15T12:31:10.500 回答