【问题标题】:Google Cloud Speech Transcription for Video Intelligence用于视频智能的 Google Cloud 语音转录
【发布时间】:2021-01-25 10:04:36
【问题描述】:

我打算使用 Google Cloud Speech Transcription for Video Intelligence。以下代码仅对视频的部分片段进行分析。

video_uri = "gs://cloudmleap/video/next/JaneGoodall.mp4"
language_code = "en-GB"
segment = types.VideoSegment()
segment.start_time_offset.FromSeconds(55)
segment.end_time_offset.FromSeconds(80)
response = transcribe_speech(video_uri, language_code, [segment])

def transcribe_speech(video_uri, language_code, segments=None):
    video_client = videointelligence.VideoIntelligenceServiceClient()
    features = [enums.Feature.SPEECH_TRANSCRIPTION]
    config = types.SpeechTranscriptionConfig(
        language_code=language_code,
        enable_automatic_punctuation=True,
    )
    context = types.VideoContext(
        segments=segments,
        speech_transcription_config=config,
    )

    print(f'Processing video "{video_uri}"...')
    operation = video_client.annotate_video(
        input_uri=video_uri,
        features=features,
        video_context=context,
    )
    return operation.result()

如何自动分析整个视频而不是定义特定片段?

【问题讨论】:

    标签: google-cloud-platform speech-recognition video-intelligence-api


    【解决方案1】:

    您可以在Video Intelligence google doc 中学习本教程。本教程展示了如何转录整个视频。您的输入应该存储在 GCS 存储桶中,我看到在您的示例代码中,您的视频确实存储在 GCS 存储桶中,因此您应该对此没有任何问题。

    只要确保你已经安装了latest Video Intelligence library.

    pip install --upgrade google-cloud-videointelligence
    

    这是用于转录音频的code snippet from the Video Intelligence doc:

    """Transcribe speech from a video stored on GCS."""
    from google.cloud import videointelligence
    
    path="gs://your_gcs_bucket/your_video.mp4"
    video_client = videointelligence.VideoIntelligenceServiceClient()
    features = [videointelligence.Feature.SPEECH_TRANSCRIPTION]
    
    config = videointelligence.SpeechTranscriptionConfig(
        language_code="en-US", enable_automatic_punctuation=True
    )
    video_context = videointelligence.VideoContext(speech_transcription_config=config)
    
    operation = video_client.annotate_video(
        request={
            "features": features,
            "input_uri": path,
            "video_context": video_context,
        }
    )
    
    print("\nProcessing video for speech transcription.")
    
    result = operation.result(timeout=600)
    
    # There is only one annotation_result since only
    # one video is processed.
    annotation_results = result.annotation_results[0]
    for speech_transcription in annotation_results.speech_transcriptions:
    
        # The number of alternatives for each transcription is limited by
        # SpeechTranscriptionConfig.max_alternatives.
        # Each alternative is a different possible transcription
        # and has its own confidence score.
        for alternative in speech_transcription.alternatives:
            print("Alternative level information:")
    
            print("Transcript: {}".format(alternative.transcript))
            print("Confidence: {}\n".format(alternative.confidence))
    
            print("Word level information:")
            for word_info in alternative.words:
                word = word_info.word
                start_time = word_info.start_time
                end_time = word_info.end_time
                print(
                    "\t{}s - {}s: {}".format(
                        start_time.seconds + start_time.microseconds * 1e-6,
                        end_time.seconds + end_time.microseconds * 1e-6,
                        word,
                    )
                )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      相关资源
      最近更新 更多