如何使用google.cloud.speech_v1p1beta1获取整个成绩单?

问题描述 投票:0回答:1

使用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

  • 使用谷歌服务帐户,没有连接问题。
  • 还将文件复制到谷歌存储并确认我可以玩
  • 尝试将文件从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个回答
0
投票

还没有与v1p1beta有任何问题,但是,在我的最后。

建议#1:可能是一个明显的建议,但你的项目是否允许“数据记录”?这是使用更高级功能/模型所必需的。也许尝试一下?如果没有改变你的结果,你可以在测试后将其关闭。

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

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

client = speech_v1p1beta1.SpeechClient()

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

sample_rate_hertz = 44100
© www.soinside.com 2019 - 2024. All rights reserved.