multimodal-speech-emotion-recognition icon indicating copy to clipboard operation
multimodal-speech-emotion-recognition copied to clipboard

extract_audio_features is not giving valid csv output

Open klep-main-klep opened this issue 3 years ago • 4 comments

The final block of third file 3_extract_audio_features is not giving proper output file. It throws "Some exception occurred" for whole of the file. What might be the issue here?`abels_df = pd.read_csv(labels_path)

for sess in (range(1, 6)): audio_vectors = pickle.load(open('{}{}.pkl'.format(audio_vectors_path, sess), 'rb')) for index, row in tqdm(labels_df[labels_df['wav_file'].str.contains('Ses0{}'.format(sess))].iterrows()): try: wav_file_name = row['wav_file'] label = emotion_dict[row['emotion']] y = audio_vectors[wav_file_name]

            feature_list = [wav_file_name, label]  # wav_file, label
            sig_mean = np.mean(abs(y))
            feature_list.append(sig_mean)  # sig_mean
            feature_list.append(np.std(y))  # sig_std

            rmse = librosa.feature.rmse(y + 0.0001)[0]
            feature_list.append(np.mean(rmse))  # rmse_mean
            feature_list.append(np.std(rmse))  # rmse_std

            silence = 0
            for e in rmse:
                if e <= 0.4 * np.mean(rmse):
                    silence += 1
            silence /= float(len(rmse))
            feature_list.append(silence)  # silence

            y_harmonic = librosa.effects.hpss(y)[0]
            feature_list.append(np.mean(y_harmonic) * 1000)  # harmonic (scaled by 1000)

            # based on the pitch detection algorithm 
            
            cl = 0.45 * sig_mean
            center_clipped = []
            for s in y:
                if s >= cl:
                    center_clipped.append(s - cl)
                elif s <= -cl:
                    center_clipped.append(s + cl)
                elif np.abs(s) < cl:
                    center_clipped.append(0)
            auto_corrs = librosa.core.autocorrelate(np.array(center_clipped))
            feature_list.append(1000 * np.max(auto_corrs)/len(auto_corrs))  # auto_corr_max (scaled by 1000)
            feature_list.append(np.std(auto_corrs))  # auto_corr_std

            df_features = df_features.append(pd.DataFrame(feature_list, index=columns).transpose(), ignore_index=True)
        except:
            print('Some exception occured')

df_features.to_csv('/content/drive/My Drive/data/pre-processed/audio_features.csv', index=False)`

It only creates CSV file of around 100 bytes. Thanks in advance!!

klep-main-klep avatar Feb 26 '21 02:02 klep-main-klep

There might be an issue with the input file. Did you check the value of other variables like labels_df?

Demfier avatar Mar 01 '21 00:03 Demfier

hi @Demfier,

I am facing the same issue. it gives "some exception occurred" for all the files. kindly help me out

ajwaaslam avatar Mar 03 '21 10:03 ajwaaslam

@ajwaaslam can you post the exact error you are facing? you can find that by moving the main logic outside of try-except (refer to #21). That will be much more helpful. I am guessing this may be due to some minor artifacts in the input. I can help more if you provide me with more concrete details.

Thanks, Gaurav.

Demfier avatar Mar 30 '21 20:03 Demfier

@Demfier Hi, according to the librosa change log for .7.0 >> (Root mean square error (rmse) has been renamed to rms). In the 3_extract_audio_features.ipynb, just change rmse = librosa.feature.rmse(y + 0.0001)[0] to rmse = librosa.feature.rms(y + 0.0001)[0]. Then everything will be not problem.

KahLiang avatar Jul 01 '21 04:07 KahLiang