The balance data consist of interaction between two people: a cluegiver and a guesser. This means that audio records both of them. For some analysis, we might want/need to separate them. For instance:
in text transcript, we will need to know what words can be attributed to whom;
for acoustic envelope, we need to separate the two voices.
In this script, we perform so-called diarization, which is the process of separating the audio into segments and attributing each segment to a speaker. As an output, we have a csv file for each wav file that tells us timestamps and the speaker.
The code is adapted from Marianne de Heer Kloots’ tutorial: https://www.envisionbox.org/embedded_Speaker_diarization_pyannote.html
Code to load packages and prepare the environment
# packagesimport osimport globimport numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom scipy.signal import butter, filtfilt, sosfiltimport librosaimport IPython.display as ipdimport seaborn as snsfrom pyannote.audio import Pipelinefrom pyannote.core.notebook import Notebookimport torchfrom IPython.display import Audioimport soundfile as sfnotebook = Notebook()curfolder = os.getcwd()datasetfolder = os.path.join(curfolder, '..', '..')# BalanceCorpusaudiofolder = os.path.join(datasetfolder, 'audios', '*') # last level for participant folderwavtotrack = glob.glob(os.path.join(audiofolder, "*.wav"))balancemeta = pd.read_csv(os.path.join(datasetfolder, 'metadata.csv'))balancedemo = pd.read_csv(os.path.join(datasetfolder, 'demographics.csv'))print('Number of audio files found: ', len(wavtotrack))# Create folder to save processed acoustic time seriesACfolder_processed = os.path.join(curfolder, '..', '..', 'TS_acoustics')ifnot os.path.exists(ACfolder_processed): os.makedirs(ACfolder_processed)