使用 Google Cloud 语音转文本仅转录音频的特定部分

问题描述

我似乎在文档中找不到任何说明。我能够从 Google Cloud 存储成功转录音频,但它转录了整个文件。为了节省成本,我只想转录部分音频,最好使用时间戳。有没有方法或变量可以做到这一点?

解决方法

您可以按照评论中的建议,首先根据时间戳拆分音频文件。以下来自 this Stackoverflow link 的 Python 代码可用于相同目的。

from pydub import AudioSegment 
t1 = t1 * 1000 #Works in milliseconds
t2 = t2 * 1000 
newAudio = AudioSegment.from_wav("oldSong.wav") 
newAudio = newAudio[t1:t2] 
newAudio.export('newSong.wav',format="wav") #Exports to a wav file in the current path.

代码使用Pydub库,支持WAV、mp3、flv等多种音频文件格式