轉錄電話來電片段
在這個練習中,我們要用 transcribe_audio() 把先前轉成 .wav 格式的音訊檔轉成文字。
由於檔案很多,而且可能還會增加,我們會撰寫一個函式 create_test_list(),輸入為音訊檔的檔名清單,逐一處理每個檔案並轉錄成文字。
create_test_list() 會呼叫我們先前建立的 transcribe_audio() 函式,並回傳一個字串清單,裡面包含每個音訊檔的轉錄文字。
pre_purchase_wav_files 和 post_purchase_wav_files 是音訊片段檔名的清單。
本練習屬於課程
Python 的口語語言處理
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
def create_text_list(folder):
# Create empty list
text_list = []
# Go through each file
for file in folder:
# Make sure the file is .wav
if file.endswith(".wav"):
print(f"Transcribing file: {file}...")
# Transcribe audio and append text to list
text_list.append(____(file))
return ____
create_text_list(folder)