Chuyển byte sóng âm thành số nguyên

Xử lý Ngôn ngữ Nói bằng Python

Daniel Bourke

Machine Learning Engineer/YouTube Creator

Chuyển bytes thành số nguyên

  • Không thể dùng bytes
  • Dùng numpy để chuyển bytes thành số nguyên
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)
Xử lý Ngôn ngữ Nói bằng Python

Tìm tốc độ khung hình

  • Tần số lấy mẫu (Hz) = độ dài mảng đối tượng sóng/độ dài tệp âm thanh (giây)
# Get the frame rate
framerate_gm = good_morning.getframerate()

# Show the frame rate framerate_gm
48,000
  • Độ dài tệp âm thanh (giây) = độ dài mảng đối tượng sóng/tần số lấy mẫu (Hz)
Xử lý Ngôn ngữ Nói bằng Python

Tìm mốc thời gian của sóng âm

# 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))
Xử lý Ngôn ngữ Nói bằng Python

Tìm mốc thời gian của sóng âm

# 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])
Xử lý Ngôn ngữ Nói bằng Python

Cùng luyện tập nào!

Xử lý Ngôn ngữ Nói bằng Python

Preparing Video For Download...