I am trying to extract audio segments from a series of audio recordings. Segment onsets and offsets to be extracted from each recording are specified in a dataframe with three columns containing a) the name of the sound recording, b) the onset of the segment, and c) the offset of the segment (see below)
segm_info_dic = {'Sentence': ['x', 'y', 'z'], 'Onset': [100, 200, 300], 'Offset': [200, 300, 400]}
segm_info_df = pd.DataFrame(data=segm_info_dic)
I then tried to loop over the audio recordings and the rows of the dataframe, so that each audio recording is segmented at the right point and then saved as a new recording.
for index, row in segm_info_df.iterrows():
for sound_file in sound_list:
sound_path = os.path.join(sound_folder, sound_file)
sound = AudioSegment.from_wav(sound_path)
w1 = sound[row['Onset']:row['Offset']]
new_sound.export(os.path.join(new_folder, w1))
However, my loop does not work since only the last audio recording in the list is segmented at the right point. I have just started using Python so I am really not sure how I should set up the loop correctly. Thank you in advance!