def excerpt_segments(segments_df,inputfile,out_dir,mono):
try:
song = AudioSegment.from_wav(inputfile)
except:
return "ERROR: "+inputfile+" can't be found."
start = float(segments_df[segments_df['Names']=="<START>"]['Instants'])
end = float(segments_df[segments_df['Names']=="<END>"]['Instants'])
start_msec = start * 1000.0
end_msec = end * 1000
clip_data = song[start_msec:end_msec]
clip_pathname=out_dir+inputfile.split('/')[-1][:-4]+'_reading_excerpt'+'.wav'
if mono==True:
clip_data=clip_data.set_channels(1)
clip_data.export(clip_pathname, format="wav", parameters=["-ar 48000", "-acodec pcm_s24le"])
评论列表
文章目录