【问题标题】:How to identify speaker using python sdk in using Azure cognitive speech translation API?如何在使用 Azure 认知语音翻译 API 时使用 python sdk 识别说话者?
【发布时间】:2021-04-06 01:08:33
【问题描述】:

我正在尝试使用 azure 文档中提供的修改后的基于事件的合成代码示例进行语音到语音翻译。但是,在此过程中,我还想识别扬声器(扬声器 1、扬声器 2),但我没有在 Python SDK 中看到可以帮助我将扬声器识别为语音=文本翻译的一部分的功能。有人可以建议在语音到文本的翻译过程中识别说话者的方法吗?下面是代码sn-p:

def translate_speech_to_text():

    translation_config = speechsdk.translation.SpeechTranslationConfig(subscription=speech_key, region=service_region)
    translation_config.speech_recognition_language = from_language
    translation_config.add_target_language(to_language)
    translation_config.voice_name = "en-GB-Susan"

    translation_config.request_word_level_timestamps()
    translation_config.output_format = speechsdk.OutputFormat(0)

    audio_input = speechsdk.AudioConfig(filename=filename)
    recognizer = speechsdk.translation.TranslationRecognizer(translation_config = translation_config, audio_config = audio_input)

    done = False

    def stop_cb(evt):
        """callback that stops continuous recognition upon receiving an event `evt`"""
        #print('CLOSING on {}'.format(evt))
        recognizer.stop_continuous_recognition()
        nonlocal done
        done = True

    all_results = []
    def handle_final_result(evt):
        #all_results.append(evt.result.text)
        #all_results.append(evt.result.translations['en'])
        all_results.append(evt.result.json)
    
    recognizer.recognized.connect(handle_final_result)
    # Connect callbacks to the events fired by the speech recognizer
    recognizer.recognizing.connect(lambda evt: print('RECOGNIZING: {}'.format(evt)))
    recognizer.recognized.connect(lambda evt: print('RECOGNIZED: {}'.format(evt)))
    recognizer.session_started.connect(lambda evt: print('SESSION STARTED: {}'.format(evt)))
    recognizer.session_stopped.connect(lambda evt: print('SESSION STOPPED {}'.format(evt)))
    #recognizer.canceled.connect(lambda evt: print('CANCELED {}'.format(evt)))
    recognizer.session_stopped.connect(stop_cb)
    recognizer.canceled.connect(stop_cb)
    
    def synthesis_callback(evt):
        print('Audio: {}'.format(len(evt.result.audio)))
        print('Reason: {}'.format(evt.result.reason))
        with open('out.wav', 'wb') as wavfile:
            wavfile.write(evt.result.audio)
   
    recognizer.synthesizing.connect(synthesis_callback)
    recognizer.start_continuous_recognition()    

    while not done:
        time.sleep(.5)
    
    print("Printing all results:")
    print(all_results)

translate_speech_to_text()

【问题讨论】:

    标签: python azure speech-recognition microsoft-cognitive speech


    【解决方案1】:

    如果你想识别说话者,你应该使用Speech Service

    推荐使用 REST API。

    Text Independent - Identify Single Speaker

    Speech ServicesC#C++JavaScriptREST中有完整的SDK,可以执行Speaker Recognition。 (我搜索了Python SDK,但没有找到可以直接识别的方法。)

    建议

    1. It is recommended to read the Speech related documents carefully and how to use this service.

    2. It is recommended to use request to send http post requests.

    【讨论】:

    • 谢谢。是的,即使我也看到了。所以我假设,目前无法使用 Python SDK 进行说话人识别。
    • @HarshadPatil 如果我的解决方案对您有帮助,请将我的答案标记为accepted,tks~
    • @HarshadPatil SpeakerRecognizer 对于 Python 语音 SDK 尚不可用,我们将在未来的版本中添加它。
    猜你喜欢
    • 2020-06-04
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多