Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- def get_features(df_in):
- features=[]
- labels = [] #empty array to store labels
- #For each species, determine how many augmentations are needed
- df_in=df_in.reset_index()
- for i in df_in.bird_id.unique():
- print('bird_id:',i)
- #all the file indices with the same bird_id
- filelist = df_in.loc[df_in.bird_id == i].index
- for j in range(0,len(filelist)):
- filename = df_in.iloc[filelist[j]].file_name
- print("full path: " + os.path.abspath(filename))
- #define the beginning time of the signal
- tstart = df_in.iloc[filelist[j]].t_min
- tend = df_in.iloc[filelist[j]].t_max #end of signal
- file_name = df_in.iloc[filelist[j]].file_name
- bird_id = i
- songtype_id = df_in.iloc[filelist[j]].songtype_id
- #Load the file
- signal, sr = librosa.load(filename,sr=28000)
- #cut the file to signal start and end
- signal_cut=signal[int(round(tstart*sr)):int(round(tend*sr))]
- #generate features & output numpy array
- data = generate_features(signal)
- features.append(data[np.newaxis,...])
- labels.append(bird_id)
- output=np.concatenate(features,axis=0)
- return(np.array(output), labels)
- #use get_features to calculate and store the features
- test_features, test_labels = get_features(pd.concat([X_test,y_test],axis=1))
- train_features, train_labels = get_features_noOS(pd.concat([X_train,y_train],axis=1))
- ERROR MESSAGE:
- bird_id: 1
- bird_id: 2
- bird_id: 3
- full path: /content/gdrive/My Drive/Personal/G12/Research/Audio files/PE (170).wav
- ---------------------------------------------------------------------------
- RuntimeError Traceback (most recent call last)
- /usr/local/lib/python3.7/dist-packages/librosa/core/audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
- 148 try:
- --> 149 with sf.SoundFile(path) as sf_desc:
- 150 sr_native = sf_desc.samplerate
- 8 frames
- /usr/local/lib/python3.7/dist-packages/soundfile.py in __init__(self, file, mode, samplerate, channels, subtype, endian, format, closefd)
- 628 format, subtype, endian)
- --> 629 self._file = self._open(file, mode_int, closefd)
- 630 if set(mode).issuperset('r+') and self.seekable():
- /usr/local/lib/python3.7/dist-packages/soundfile.py in _open(self, file, mode_int, closefd)
- 1183 _error_check(_snd.sf_error(file_ptr),
- -> 1184 "Error opening {0!r}: ".format(self.name))
- 1185 if mode_int == _snd.SFM_WRITE:
- /usr/local/lib/python3.7/dist-packages/soundfile.py in _error_check(err, prefix)
- 1356 err_str = _snd.sf_error_number(err)
- -> 1357 raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
- 1358
- RuntimeError: Error opening 'PE (170).wav': System error.
- During handling of the above exception, another exception occurred:
- FileNotFoundError Traceback (most recent call last)
- <ipython-input-93-597fbf317426> in <module>()
- 29 return(np.array(output), labels)
- 30 #use get_features to calculate and store the features
- ---> 31 test_features, test_labels = get_features(pd.concat([X_test,y_test],axis=1))
- 32 train_features, train_labels = get_features_noOS(pd.concat([X_train,y_train],axis=1))
- <ipython-input-93-597fbf317426> in get_features(df_in)
- 19 #TO FOLLOW songtype_id = df_in.iloc[filelist[j]].songtype_id
- 20 #Load the file
- ---> 21 signal, sr = librosa.load(filename,sr=28000)
- 22 #cut the file to signal start and end
- 23 #TO FOLLOW y_cut=y[int(round(tstart*sr)):int(round(tend*sr))]
- /usr/local/lib/python3.7/dist-packages/librosa/core/audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
- 164 if isinstance(path, (str, pathlib.PurePath)):
- 165 warnings.warn("PySoundFile failed. Trying audioread instead.")
- --> 166 y, sr_native = __audioread_load(path, offset, duration, dtype)
- 167 else:
- 168 raise (exc)
- /usr/local/lib/python3.7/dist-packages/librosa/core/audio.py in __audioread_load(path, offset, duration, dtype)
- 188
- 189 y = []
- --> 190 with audioread.audio_open(path) as input_file:
- 191 sr_native = input_file.samplerate
- 192 n_channels = input_file.channels
- /usr/local/lib/python3.7/dist-packages/audioread/__init__.py in audio_open(path, backends)
- 109 for BackendClass in backends:
- 110 try:
- --> 111 return BackendClass(path)
- 112 except DecodeError:
- 113 pass
- /usr/local/lib/python3.7/dist-packages/audioread/rawread.py in __init__(self, filename)
- 60 """
- 61 def __init__(self, filename):
- ---> 62 self._fh = open(filename, 'rb')
- 63
- 64 try:
- FileNotFoundError: [Errno 2] No such file or directory: 'PE (170).wav'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement