Wheel command line tool (enable python -m wheel syntax)
import sys
defmain(): # needed for console script if __package__ == '': # To be able to run 'python wheel-0.9.whl/wheel': import os.path path = os.path.dirname(os.path.dirname(__file__)) sys.path[0:0] = [path] import wheel.cli sys.exit(wheel.cli.main())
# filepath = 'offline-test-data-1-mono' # filepath = 'offline-test-data-2-stereo-to-mono' filepath = "offline-test-data-3-stereo" # outpath1 is where the rttm files store outpath1 = "{filepath}/rttm/".format(filepath=filepath) # outpath2 is where the sad files store outpath2 = "{filepath}/sad/".format(filepath=filepath)
# filepath/textgrid is where the textgrid files of recordings store files = os.listdir("{filepath}/textgrid/".format(filepath=filepath))
# for each textgrid file, extract the speech segments and write them into rttm files for file in files: print("--------------------") filename = file.split(".")[0] print(filename) withopen( "{filepath}/textgrid/{file}".format(filepath=filepath, file=file), "r" ) as f: out = [] lines = f.readlines() lines = [line[:-1] for line in lines] for i, line inenumerate(lines): iflen(line) > 2andlen(line) < 10and line[0] == '"': if line[-1] == '"'andnot ( line == '"6"' or line == '"1"' or line == '"2"' or line == '"TextGrid"' or line == '"IntervalTier"' or line == '"全局层"' or line == '"文本层"' or line == '"角色层"' or line == '"[ENS]"' or line == '"[SIL]"' ): # if line[1] == "[" or line == "\"+\"": if line == '"+"': s = lines[i - 2] print(s) e = lines[i - 1] print(e) duration = round((float(e) - float(s)), 3) print(duration) print(line) print(" ") outputline1 = "SPEAKER {filename}_B1 {s} {duration} <NA> <NA> {filename}{speaker} <NA> <NA>\n".format( filename=filename, s=s, duration=duration, speaker="+" ) # print(outputline1) outputline2 = "{s} {e} speech\n".format(s=s, e=e) # print(outputline2) withopen( "{filepath}/rttm_AB_new/{filename}_B.rttm".format( filepath=filepath, filename=filename ), "a", ) as f: f.write(outputline1) withopen( "{filepath}/sad_AB_new/{filename}_A.lab".format( filepath=filepath, filename=filename ), "a", ) as f: f.write(outputline2)