Last active
August 1, 2017 12:12
-
-
Save lttzzlll/46f85d5d8d10d4d89e52d16318b784a3 to your computer and use it in GitHub Desktop.
task 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Python Training | |
https://microsoft.sharepoint.com/teams/stca/ipe/sr/_layouts/15/WopiFrame.aspx?sourcedoc={57bcddd2-341f-4151-84f7-f332fca4d07a}&action=edit&wd=target%28LearningCorner%2Eone%7CDF7F96A9-2186-462F-A0EC-8772881176AA%2FPerl%20and%20C%23%20Training%7C1C6AD0B9-765A-4DD5-A3C7-0822927FC9D1%2F%29 | |
''' | |
import xml.etree.ElementTree as ET | |
from operator import itemgetter | |
import argparse | |
SRC_FILE_NAME = 'ITA_Blind_R2.xml' | |
DES_FILE_NAME = 'task1_output.txt' | |
def run(src, des): | |
''' | |
start program | |
''' | |
speakers = {} | |
tree = ET.ElementTree(file=src) | |
for elem in tree.iter('SpeechIn'): | |
speaker, session, wav = elem.attrib.get('WaveFilePath').split('\\') | |
if speaker not in speakers: | |
speakers[speaker] = [] | |
speakers[speaker].append((session, wav)) | |
speakers = speakers.items() | |
speakers = sorted(speakers, key=itemgetter(0)) | |
with open(des, 'w') as fp: | |
for speaker, context in speakers: | |
fp.write(speaker + '\n') | |
for session, wav in context: | |
fp.write('\\'.join((speaker, session, wav)) + '\n') | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='process file') | |
parser.add_argument('--src', type=str, default=SRC_FILE_NAME, help='source file path') | |
parser.add_argument('--des', type=str, default=DES_FILE_NAME, help='destination file path') | |
args = parser.parse_args() | |
run(src=args.src, des=args.des) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment