【问题标题】:Azure Speech SDK | Python | Implementing Keyword RecognitionAzure 语音 SDK |蟒蛇 |实施关键字识别
【发布时间】:2020-09-14 14:50:05
【问题描述】:

我正在尝试使用 Azure 认知服务和 Python 创建自定义唤醒词。我正在关注快速入门教程 -

azure quickstart

我已经使用语音工作室生成了关键字模型,现在我正在尝试在 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: 'Recognizer' 对象没有属性 '_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

【问题讨论】:

    标签: python speech-recognition azure-speech


    【解决方案1】:

    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 Samples

    【讨论】:

      猜你喜欢
      • 2016-04-11
      • 2014-12-08
      • 2012-03-20
      • 1970-01-01
      • 1970-01-01
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多