1 Question: How can i feature extraction (.wav) form folders and sub-folders for using as input of the neural network?

question created at Sat, Jun 1, 2019 12:00 AM

This is my code, please help me to correct:

from pathlib import Path
from python_speech_features import fbank
import scipy.io.wavfile as wavfile

path = Path('/home/narges/dataset/seri1.16khz.128kbps/Voice   Recorder/N00xxxx/').glob('*/*.wav')
wavs = [str(wavf) for wavf in path if wavf.is_file()]
wavs.sort()

print(wavs)

number_of_files=len(wavs)

wav_data=[]

for i in range(number_of_files):
    samplerate, data=wavfile.read(wavs[i])
    wav_data.append(data)
print(wav_data)

fbank_feat=fbank(samplerate, data)
print(fbank_feat)

my error is: 'int' object is not subscriptable. How can i correct this?

0
  1. Please provide the full error traceback. The full traceback is extremely useful, the last line in the traceback is usually useless.
    2019-06-01 04:33:22Z
  2. In line 25 (for loop) i have this error.
    2019-06-01 04:44:56Z
  3. Your trying to read an entire list, read each file individually: data=wavfile.read(wavs[i])
    2019-06-01 04:46:45Z
  4. So thanks. With this code (samplerate, data=wavfile.read(wavs[i])my error is corrected but in line 30, i have this error: 'int' object is not subscriptable.
    2019-06-01 04:50:49Z
  5. Please add that code you your question. You don't do and sub scripting in the provided code.
    2019-06-01 04:54:13Z
1 Answers 1

Finally i used this code and it's correct:

from pathlib import Path
from python_speech_features import fbank
import scipy.io.wavfile as wavfile
import numpy as np

path = Path('/home/narges/dataset/seri1.16khz.128kbps/Voice Recorder/N00xxxx/').glob('*/*.wav')
wavs = [str(wavf) for wavf in path if wavf.is_file()]
wavs.sort()
print(wavs)

number_of_files=len(wavs)

for i in range(number_of_files):
    (rate, sig) = wavfile.read(wavs[i])

fbank_feat=fbank(sig, rate, winlen=0.06, winstep=0.01, nfilt=26, nfft=512, lowfreq=0, highfreq=rate/2, preemph=0.97, winfunc=np.hamming)
print(fbank_feat)
0
2019-06-01 09:45:52Z
source placed here