前提・実現したいこと
音声認識の前処理としてフレームの切り出しを行いたい
発生している問題・エラーメッセージ
Traceback (most recent call last): File "framecut.py", line 42, in <module> cutting(x,fs) File "framecut.py", line 22, in cutting save(y,fs,16,"cut/cuttedsound_"+str(m)+'.wav') File "framecut.py", line 32, in save wf.writeframes(data) File "/home/hoge/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/wave.py", line 427, in writeframes self.writeframesraw(data) File "/home/hoge/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/wave.py", line 415, in writeframesraw data = memoryview(data).cast('B') TypeError: memoryview: a bytes-like object is required, not 'list'
該当のソースコード
python3.6.3
1#coding:utf-8 2import wave 3import struct 4from pylab import * 5 6def cutting(x,fs): 7 frameSize = 0.025 8 frameShift = 0.010 9 10 frameSizeSample = int(fs * frameSize) 11 frameShiftSample = int(fs * frameShift) 12 13 maxFrame = int((len(x) - (frameSizeSample - frameShiftSample) / frameShiftSample ) -1) 14 15 startThisFrame = 0 16 endThisFrame = startThisFrame + frameSizeSample 17 18 for n in range(maxFrame): 19 y = [0.0] * frameSizeSample 20 for m in range(frameSizeSample): 21 y[m] = x[m + startThisFrame] 22 save(y,fs,16,"cut/cuttedsound_"+str(m)+'.wav') 23 startThisFrame = startThisFrame + frameShiftSample 24 25 26def save(data, fs, bit, filename): 27 """波形データをWAVEファイルへ出力""" 28 wf = wave.open(filename, "w") 29 wf.setnchannels(1) 30 wf.setsampwidth(bit // 8) 31 wf.setframerate(fs) 32 wf.writeframes(data) 33 wf.close() 34 35if __name__ == '__main__': 36 wf = wave.open("data/combined_sine.wav", "r") 37 fs = wf.getframerate() 38 39 x = wf.readframes(wf.getnframes()) 40 x = frombuffer(x, dtype="int16") // 32768.0 #-1 ~ 1 41 42 cutting(x,fs) 43
補足情報(FW/ツールのバージョンなど)
こちらのサイトのフレーム切り出しの項目を参考にしました
http://speechresearch.fiw-web.net/73.html#q962d911

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/05 06:54