將聲波位元組轉成整數

Python 的口語語言處理

Daniel Bourke

Machine Learning Engineer/YouTube Creator

將位元組轉成整數

  • 無法直接使用位元組
  • 用 numpy 將位元組轉成整數
import numpy as np

# Convert soundwave_gm from bytes to integers signal_gm = np.frombuffer(soundwave_gm, dtype='int16')
# Show the first 10 items signal_gm[:10]
array([ -3,  -5,  -8,  -8,  -9, -13,  -8, -10,  -9, -11], dtype=int16)
Python 的口語語言處理

找出取樣頻率(frame rate)

  • 頻率(Hz)= 波形陣列長度/音訊長度(秒)
# Get the frame rate
framerate_gm = good_morning.getframerate()

# Show the frame rate framerate_gm
48,000
  • 音訊長度(秒)= 波形陣列長度/頻率(Hz)
Python 的口語語言處理

取得聲波的時間戳

# Return evenly spaced values between start and stop
np.linspace(start=1, stop=10, num=10)
array([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.])
# Get the timestamps of the good morning sound wave
time_gm = np.linspace(start=0, 
                      stop=len(soundwave_gm)/framerate_gm,
                      num=len(soundwave_gm))
Python 的口語語言處理

取得聲波的時間戳

# View first 10 time stamps of good morning sound wave
time_gm[:10]
array([0.00000000e+00, 2.08334167e-05, 4.16668333e-05, 6.25002500e-05,
       8.33336667e-05, 1.04167083e-04, 1.25000500e-04, 1.45833917e-04,
       1.66667333e-04, 1.87500750e-04])
Python 的口語語言處理

一起來練習吧!

Python 的口語語言處理

Preparing Video For Download...