サウンドウェーブのバイトを整数に変換する

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で学ぶ音声言語処理

フレームレートを調べる

  • サンプリング周波数(Hz)= wave オブジェクト配列の長さ ÷ 音声ファイルの長さ(秒)
# Get the frame rate
framerate_gm = good_morning.getframerate()

# Show the frame rate framerate_gm
48,000
  • 音声ファイルの長さ(秒)= wave オブジェクト配列の長さ ÷ サンプリング周波数(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...