小编Pyt*_*ong的帖子

Python 中的 Microsoft Azure 语音转文本功能的字幕/说明文字

我一直试图弄清楚如何使用 Python 中的 Microsoft Azure 语音识别服务制作字幕,但无法弄清楚。我遵循了其他人在这里回答的关于获取单个单词的提示,但即使将它们格式化为 .srt 或 .vtt 似乎也很复杂。这是代码:

import azure.cognitiveservices.speech as speechsdk


def speech_recognize_continuous_from_file():
    """performs continuous speech recognition with input from an audio file"""
    # <SpeechContinuousRecognitionWithFile>
    speech_key, service_region = "{api-key}", "{serive-region}"
    speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
    
    audio_filename = "{for example: video.wav}"
    audio_config = speechsdk.audio.AudioConfig(filename=audio_filename)
    
    speech_config.speech_recognition_language="en-US"
    speech_config.request_word_level_timestamps()

    speech_config.enable_dictation()
    speech_config.output_format = speechsdk.OutputFormat(1)
    
    speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)

    done = False
    
    results = []
    
    transcript = []
    words = []
    
    def handle_final_result(evt):
        import json
        results = json.loads(evt.result.json)
        transcript.append(results['DisplayText'])
    confidence_list_temp = [item.get('Confidence') for item …
Run Code Online (Sandbox Code Playgroud)

python speech-recognition azure speech-to-text subtitle

5
推荐指数
1
解决办法
3792
查看次数