轉錄電話通話片段
在這個練習中,我們會使用 transcribe_audio(),把先前轉成 .wav 格式的音訊檔轉錄成文字。
因為檔案很多,之後也可能會更多,所以我們要建立一個函式 create_text_list()。它會把音訊檔檔名的清單作為輸入,逐一讀取每個檔案並轉錄成文字。
create_text_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)