使用Google语音转文字,我只会得到部分转录。 输入文件:来自Google示例音频文件
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) ✗
Env:使用python3
当发言人更换时,我正在尝试获得带时间戳的全部录音。
所需的输出
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.
希望您能提供帮助。
答案 0 :(得分:0)
到目前为止,v1p1beta还没有任何问题。
建议1:也许是一个明显的建议,但是您的项目是否允许“数据记录”?使用更高级的功能/模型是必需的。也许尝试一下?如果没有改变结果,您可以在测试后将其关闭。
数据记录参考:https://cloud.google.com/speech-to-text/docs/data-logging
建议2:尝试在下面使用此行:
client = speech_v1p1beta1.SpeechClient()
建议3::尝试在配置中添加采样率
sample_rate_hertz = 44100