Advertisement
Guest User

Untitled

a guest
Jan 13th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.21 KB | None | 0 0
  1. import pandas as pd
  2. def get_features(df_in):  
  3.     features=[]    
  4.     labels = [] #empty array to store labels    
  5.     #For each species, determine how many augmentations are needed
  6.     df_in=df_in.reset_index()    
  7.     for i in df_in.bird_id.unique():
  8.            print('bird_id:',i)    
  9.            #all the file indices with the same bird_id    
  10.            filelist = df_in.loc[df_in.bird_id == i].index        
  11.     for j in range(0,len(filelist)):      
  12.             filename = df_in.iloc[filelist[j]].file_name
  13.             print("full path: " + os.path.abspath(filename))
  14.             #define the beginning time of the signal          
  15.             tstart = df_in.iloc[filelist[j]].t_min            
  16.             tend = df_in.iloc[filelist[j]].t_max #end of signal
  17.             file_name = df_in.iloc[filelist[j]].file_name
  18.             bird_id = i
  19.             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.             signal_cut=signal[int(round(tstart*sr)):int(round(tend*sr))]  
  24.             #generate features & output numpy array          
  25.             data = generate_features(signal)
  26.             features.append(data[np.newaxis,...])    
  27.             labels.append(bird_id)    
  28.             output=np.concatenate(features,axis=0)    
  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))
  33.  
  34.  
  35.  
  36.  
  37. ERROR MESSAGE:
  38.  
  39.  
  40.  
  41. bird_id: 1
  42. bird_id: 2
  43. bird_id: 3
  44. full path: /content/gdrive/My Drive/Personal/G12/Research/Audio files/PE (170).wav
  45. ---------------------------------------------------------------------------
  46. RuntimeError                              Traceback (most recent call last)
  47. /usr/local/lib/python3.7/dist-packages/librosa/core/audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
  48.     148     try:
  49. --> 149         with sf.SoundFile(path) as sf_desc:
  50.     150             sr_native = sf_desc.samplerate
  51.  
  52. 8 frames
  53. /usr/local/lib/python3.7/dist-packages/soundfile.py in __init__(self, file, mode, samplerate, channels, subtype, endian, format, closefd)
  54.     628                                          format, subtype, endian)
  55. --> 629         self._file = self._open(file, mode_int, closefd)
  56.     630         if set(mode).issuperset('r+') and self.seekable():
  57.  
  58. /usr/local/lib/python3.7/dist-packages/soundfile.py in _open(self, file, mode_int, closefd)
  59.    1183         _error_check(_snd.sf_error(file_ptr),
  60. -> 1184                      "Error opening {0!r}: ".format(self.name))
  61.    1185         if mode_int == _snd.SFM_WRITE:
  62.  
  63. /usr/local/lib/python3.7/dist-packages/soundfile.py in _error_check(err, prefix)
  64.    1356         err_str = _snd.sf_error_number(err)
  65. -> 1357         raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
  66.    1358
  67.  
  68. RuntimeError: Error opening 'PE (170).wav': System error.
  69.  
  70. During handling of the above exception, another exception occurred:
  71.  
  72. FileNotFoundError                         Traceback (most recent call last)
  73. <ipython-input-93-597fbf317426> in <module>()
  74.      29             return(np.array(output), labels)
  75.      30 #use get_features to calculate and store the features
  76. ---> 31 test_features, test_labels = get_features(pd.concat([X_test,y_test],axis=1))
  77.      32 train_features, train_labels = get_features_noOS(pd.concat([X_train,y_train],axis=1))
  78.  
  79. <ipython-input-93-597fbf317426> in get_features(df_in)
  80.      19             #TO FOLLOW songtype_id = df_in.iloc[filelist[j]].songtype_id
  81.      20             #Load the file
  82. ---> 21             signal, sr = librosa.load(filename,sr=28000)
  83.      22             #cut the file to signal start and end
  84.      23             #TO FOLLOW y_cut=y[int(round(tstart*sr)):int(round(tend*sr))]
  85.  
  86. /usr/local/lib/python3.7/dist-packages/librosa/core/audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
  87.     164         if isinstance(path, (str, pathlib.PurePath)):
  88.     165             warnings.warn("PySoundFile failed. Trying audioread instead.")
  89. --> 166             y, sr_native = __audioread_load(path, offset, duration, dtype)
  90.     167         else:
  91.     168             raise (exc)
  92.  
  93. /usr/local/lib/python3.7/dist-packages/librosa/core/audio.py in __audioread_load(path, offset, duration, dtype)
  94.     188
  95.     189     y = []
  96. --> 190     with audioread.audio_open(path) as input_file:
  97.     191         sr_native = input_file.samplerate
  98.     192         n_channels = input_file.channels
  99.  
  100. /usr/local/lib/python3.7/dist-packages/audioread/__init__.py in audio_open(path, backends)
  101.     109     for BackendClass in backends:
  102.     110         try:
  103. --> 111             return BackendClass(path)
  104.     112         except DecodeError:
  105.     113             pass
  106.  
  107. /usr/local/lib/python3.7/dist-packages/audioread/rawread.py in __init__(self, filename)
  108.      60     """
  109.     61     def __init__(self, filename):
  110. ---> 62         self._fh = open(filename, 'rb')
  111.     63
  112.     64         try:
  113.  
  114. FileNotFoundError: [Errno 2] No such file or directory: 'PE (170).wav'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement