【问题标题】:How to get entire transcript using google.cloud.speech_v1p1beta1?如何使用 google.cloud.speech_v1p1beta1 获取整个成绩单?
【发布时间】:2019-02-14 17:51:20
【问题描述】:

使用 Google-Speech-to-Text,我只能获得部分转录。 输入文件:来自谷歌示例音频文件

Link to google repo location Commercial_mono.wav

这是我的代码:

def transcribe_gcs(gcs_uri):
from google.cloud import speech_v1p1beta1 as speech
from google.cloud.speech_v1p1beta1 import enums
from google.cloud.speech_v1p1beta1 import types
client = speech.SpeechClient()
audio = types.RecognitionAudio(uri = gcs_uri)
config = speech.types.RecognitionConfig( language_code = 'en-US',enable_speaker_diarization=True, diarization_speaker_count=2)
operation = client.long_running_recognize(config, audio)


print('Waiting for operation to complete...')
response = operation.result(timeout=5000)
result = response.results[-1]

words_info = result.alternatives[0].words

tag=1
speaker=" "

for word_info in words_info:
    if word_info.speaker_tag==tag:
        speaker=speaker+" "+word_info.word

    else:
        print("speaker {}: {}".format(tag,speaker))
        tag=word_info.speaker_tag
        speaker=" "+word_info.word

这是我如何调用脚本:

transcribe_gcs('gs://mybucket0000t/commercial_mono.wav')

我只从整个音频文件中获得部分转录

(venv3) ➜  g-transcribe git:(master) ✗ python gtranscribeWithDiarization.py
Waiting for operation to complete...
speaker 1:   I'm here
speaker 2:  hi I'd like to buy a Chrome Cast and I was wondering whether you 
could help me

这就是我的全部

如果我多次执行代码,在 5 或 6 次之后,我不会收到任何转录。

这是几次尝试后的结果:

(venv3) ➜  g-transcribe git:(master) ✗ python gtranscribeWithDiarization.py

Waiting for operation to complete...
speaker 1:  

(venv3) ➜  g-transcribe git:(master) ✗ 

环境:使用 python3

  • 使用 google 服务帐户,连接没有问题。
  • 还将文件复制到谷歌存储并确认我可以玩
  • 尝试将文件从 wav 转换为 flac 但结果 是一样的
  • 使用 ffprobe 确保只有一个通道

我正在尝试在扬声器更改时获取带有时间戳的整个转录。

期望的输出

Speaker 1: Start Time 0.0001: Hello transcription starts
Speaker 2: Start Time 0.0009: Here starts with the transcription of the 2nd speaker and so on to the end of file.

希望您能提供帮助。

【问题讨论】:

    标签: python-3.x google-cloud-platform speech-to-text google-speech-api google-cloud-speech


    【解决方案1】:

    对我而言,v1p1beta 没有任何问题。

    建议 #1: 可能是一个显而易见的建议,但您的项目是否允许“数据记录”?使用更高级的功能/模型需要它。也许试试看?如果它不会改变您的结果,您可以在测试后将其关闭。

    数据记录参考:https://cloud.google.com/speech-to-text/docs/data-logging

    建议 #2: 尝试使用下面的这一行:

    client = speech_v1p1beta1.SpeechClient()
    

    建议 #3: 尝试在配置中添加采样率

    sample_rate_hertz = 44100
    

    【讨论】:

    • 您是否尝试过我问题中带有链接的代码?是的,我已经启用了数据记录。
    • 不,我没有,我只是让它为我自己的文件工作。您是否尝试过建议 2?
    • 是的,我做到了,但如果你仔细观察,这与我在“从 google.cloud 导入 Speech_v1p1beta1 作为语音”中所做的相同,但我确实尝试过。你在运行 long_running_recognize 吗?你的音频文件有多大? 30 分钟还是 60 分钟?
    • 是的,长时间运行,15 分钟到 35 分钟。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多