-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun_mts_measures.py
More file actions
86 lines (63 loc) · 2.53 KB
/
Copy pathrun_mts_measures.py
File metadata and controls
86 lines (63 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
## Script for running multitaper script on all SPADE corpora
## James Tanner Nov 2020
import subprocess
import re
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("InputDir", help = "Path to the list of sibilant files")
parser.add_argument("SoundDir", help = "Path to the top level of sound files")
parser.add_argument("OutputDir", help = "Path to write out CSVs")
parser.add_argument("-b", "--batch", help = "Run script on defined batch", action = "store_true")
args = parser.parse_args()
## batch to run: fill if necessary
b = []
## skipped corpora
skipped = []
## corpora with subdirs
subdirs = ['spade-Buckeye', 'spade-dapp-EnglandLDS', 'spade-dapp-Ireland', 'spade-dapp-Scotland',
'spade-dapp_ScotlandNE', 'spade-dapp-Wales', 'spade-DECTE', 'spade-Edinburgh',
'spade-GlasgowBiD', 'spade-Glaswasian', 'spade-ICE_Sco', 'spade-Irish', 'spade-IViE-Belfast',
'spade-IViE-Bradford', 'spade-IViE-Cambridge', 'spade-IViE-Cardiff', 'spade-IViE-Dublin',
'spade-IViE-Leeds', 'spade-IViE-London', 'spade-IViE-Newcastle', 'spade-PAC-Ayr',
'spade-PEBL', 'spade-PettyHarbour', 'spade-Raleigh', 'spade-SOTC', 'spade-TIMIT']
## corpora with numbers as discourse name
numbers = ["spade-WYRED"]
## corpora that use speaker name instead of discourse
speakers = ['spade-DECTE']
def getCorpusName(file):
"""Extract corpus name from CSV file"""
corpus = re.search("(spade-.*)_sibilants.csv", file).group(1)
return corpus
def runMTS(corpus, file, flag = []):
"""Call R process to run mts script"""
inPath = os.path.join(args.InputDir, file)
SoundPath = os.path.join(args.SoundDir, corpus, "audio_and_transcripts")
## command line call
cmd = ['Rscript', 'generate_mts_measures.r', inPath, SoundPath, args.OutputDir]
## insert flags into command line call
if len(flag) > 0:
for i, fl in enumerate(flag):
cmd.insert(i + 2, fl)
## make R call
print(cmd)
subprocess.call(cmd)
def processFile(file, f = []):
"""Get corpus name and run MTS
script with arguments"""
if file.endswith("csv"):
corpus = getCorpusName(file)
if corpus in skipped:
return
if corpus in subdirs:
f.append('-d')
if corpus in numbers:
f.append('-n')
if corpus in speakers:
f.append('-s')
runMTS(corpus, file, flag = f)
## run over directory
if args.batch:
list(map(processFile, b))
else:
list(map(processFile, os.listdir(args.InputDir)))