使用Python批量转录wav文件可以通过以下步骤实现:
import wave
import speech_recognition as sr
def batch_transcribe(folder_path):
r = sr.Recognizer()
files = glob.glob(os.path.join(folder_path, "*.wav")) # 获取文件夹中所有的wav文件
for file in files:
with sr.AudioFile(file) as source:
audio = r.record(source) # 将音频文件加载到Memory中
try:
text = r.recognize_google(audio, language="en-US") # 使用Google语音识别API进行转录
print(f"Transcription of {file}: {text}") # 打印转录结果
except sr.UnknownValueError:
print(f"Transcription of {file}: Could not understand audio")
except sr.RequestError as e:
print(f"Transcription of {file}: Error occurred during transcription: {str(e)}")
folder_path = "path/to/folder"
batch_transcribe(folder_path)
请注意,上述代码假设您已经安装了speech_recognition库。如果尚未安装,请使用以下命令进行安装:
pip install SpeechRecognition
这是一个使用Python批量转录wav文件的简单示例。您可以根据需要进行修改和定制。
领取专属 10元无门槛券
手把手带您无忧上云