開始使用免費開始

用 Python 處理音訊資料

你已經看過如何把聲波轉成數字,但整個轉換流程實際上長什麼樣子?

那另一段相似、但稍微不同的聲波呢?

在這個練習中,你將使用 MatPlotLib 繪製 good_morninggood_afternoon 的聲波。

為了把 good_morninggood_afternoon 的聲波畫在同一張圖上,且彼此容易分辨,我們會使用 MatPlotLib 的 alpha 參數。

你可以在這裡收聽 good_morning 音訊:here,以及這裡收聽 good_afternoon 音訊:here

本練習屬於課程

Python 的口語語言處理

檢視課程

練習說明

  • 設定標題,讓它能反映這張圖的內容。
  • good_afternoon 的時間變數(time_ga)與振幅變數(soundwave_ga)加入圖中。
  • 以同樣方式,將 good_morning 的時間變數(time_gm)與振幅變數(soundwave_gm)加入圖中。
  • 將 alpha 參數設定為 0.5

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Setup the title and axis titles
plt.title('Good Afternoon vs. Good ____')
plt.ylabel('Amplitude')
plt.xlabel('Time (seconds)')

# Add the Good Afternoon data to the plot
plt.plot(____, ____, label='Good Afternoon')

# Add the Good Morning data to the plot
plt.plot(____, ____, label='Good Morning',
   # Set the alpha variable to 0.5
   alpha=____)

plt.legend()
plt.show()
編輯並執行程式碼