'''
Attempts to split a call file into different segments each time the speaker changes using
speaker diarization. This method assumes there are two speakers in the file (sales and customer)
and will cut out dial tones and any receptionists before the two speakers' conversation.
no_rings_out_dir = os.path.join(out_loc, 'calls_no_ringtones')
if not os.path.exists(no_rings_out_dir):
os.makedirs(no_rings_out_dir)
diarized_out_dir = os.path.join(out_loc, 'calls_split_by_speaker')
if not os.path.exists(diarized_out_dir):
os.makedirs(diarized_out_dir)
print(call_file)
raw_audio = AudioSegment.from_file(call_file, 'wav')
file_name = os.path.splitext(os.path.basename(call_file))[0]
curr_path = os.path.dirname(os.path.realpath(__file__))
ring_labels = aS.hmmSegmentation(call_file, os.path.join(curr_path, 'hmmRingDetect'), False)
segs, flags = aS.flags2segs(ring_labels[0], 1.0)
no_rings_audio = raw_audio[segs[-1, 0]*1000:segs[-1, 1]*1000]
temp_out_loc = os.path.join(no_rings_out_dir, file_name) + '.wav'
no_rings_audio.export(temp_out_loc, format='wav')
diarized = aS.speakerDiarization(temp_out_loc, 2, mtSize=0.5, mtStep=0.1)
cust = diarized[0]