# Praat script: SegmentLongWAVFilesToSmallOnes.praat # Author: Pengfei Shao . revised by Qibin Ran. # Version: 2014/5/28 14:16:00; 2018/11/28 # Praat Version 6.0.19 # Purpose: Divide the discourse into slices according to the label of Tier # # Requires: # # Version History: # 2014/5/28: Praat script is created. # 2016/08/19: Change to Simple version. # 2018/11/28: Save sound files with names as the texts annotated in text grids. ################################################## form dialogue comment 请输入源声音文件和标注文件所在目录: text openpath C:\Users\ran\Desktop\擦音切分\2 comment 请输入切分后声音保存目录: text savepath C:\Users\ran\Desktop\擦音切分\2 comment 请输入标记所在层级及标记内容: positive tier_number 3 sentence mark_string endform if right$(openpath$,1) <> "\" openpath$ = openpath$ + "\" endif if right$(savepath$,1) <> "\" savepath$ = savepath$ + "\" endif createDirectory: savepath$ Create Strings as file list: "fileList", openpath$ + "*.wav" numofFiles = Get number of strings for i from 1 to numofFiles selectObject: "Strings fileList" fileName$ = Get string: i order = 1 Read from file: openpath$ + fileName$ nameOfFile$ = selected$("Sound") textgridNameOfFile$ = nameOfFile$ + ".TextGrid" Read from file: openpath$ + textgridNameOfFile$ numOfIntervals = Get number of intervals: tier_number for j from 1 to numOfIntervals selectObject: "TextGrid " + nameOfFile$ startTime = Get start point: tier_number, j endTime = Get end point: tier_number, j labelOfInterval$ = Get label of interval: tier_number, j if (labelOfInterval$ = mark_string$ and mark_string$ <> "") or (labelOfInterval$ <> "" and mark_string$ = "") Extract part: startTime, endTime, "no" selectObject: "Sound " + nameOfFile$ Extract part: startTime, endTime, "rectangular", 1, "no" ## selectObject: "Sound " + nameOfFile$ + "_part" Save as WAV file: savepath$ + labelOfInterval$ + ".wav" selectObject: "Sound " + nameOfFile$ + "_part" Remove selectObject: "TextGrid " + nameOfFile$ + "_part" Remove order = order + 1 endif endfor selectObject: "TextGrid " + nameOfFile$ Remove selectObject: "Sound " + nameOfFile$ Remove endfor select Strings fileList Remove exit Over!