Google SpeechttoText Dialization python SDK

2024-04-30 00:29:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试构建一个Python应用程序来使用Google Cloud Speech-to-Text API转录音频记录。因为它涉及多个演讲者之间的对话,所以我想实现speaker diarization。然而,STT似乎只提供单词级的日记:

The transcription result tags each word with a number assigned to individual speakers. Words spoken by the same speaker bear the same number.

因为我想转录对话,我更喜欢在句子层面上进行日记。我尝试过类似的方法(基于此example):

# Handling audio stream happens before this

transcript = ''

tag = 1
speaker = ''

for word_info in words_info:
    if word_info.speaker_tag == tag:
        speaker = speaker + ' ' + word_info.word
    else:
        transcript += 'speaker {}: {}'.format(tag, speaker) + '\n'
        tag = word_info.speaker_tag
        speaker = ' ' + word_info.word

transcript += 'speaker {}: {}'.format(tag, speaker)

然而,这种方法很难确定一个演讲者何时结束,另一个演讲者何时开始。确定这一点的唯一方法是根据扬声器之间的变化。这可能会导致一些问题。这也使得使用SDK的某些功能变得更加困难,例如自动添加标点符号

有没有更好的办法


Tags: theto方法info应用程序formatnumbertag