-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
235 lines (214 loc) · 7.26 KB
/
build.gradle
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "de.dfki.mary:marytts-client:5.2"
}
}
plugins {
id 'de.dfki.mary.voicebuilding-legacy' version '5.2.0'
id "de.undercouch.download" version "3.2.0"
}
group 'de.uni-saarland.coli.voicebuilding2016WS.group1'
version '0.3-SNAPSHOT'
voice {
name = 'endru'
gender = 'male'
}
import de.undercouch.gradle.tasks.download.Download
import marytts.util.data.audio.MaryAudioUtils
import marytts.util.dom.MaryDomUtils
// download the .zip file from the second release containing normalized .wav files
task downloadWavZip(type: Download) {
src 'https://github.com/yoshegg/voice-andrew-us-data/releases/download/audio_normalized/normalized_wavs.zip'
dest buildDir
overwrite false
}
// extract this .wav files into our build directory
task unpackWav(type: Copy) {
from zipTree("$buildDir/normalized_wavs.zip")
into "$buildDir/wav/"
dependsOn downloadWavZip
}
// download a copy of the data repository
task downloadMetadata(type: Download) {
src 'https://github.com/yoshegg/voice-andrew-us-data/archive/master.zip'
dest "$buildDir/metadata.zip"
// overwrite false
// apparently this does not work, but our data repository is very small
onlyIfNewer true
}
// extract the .txt files to our build directory
task unpackText(type: Copy) {
from zipTree("$buildDir/metadata.zip"), {
include '**/txt/*.txt'
eachFile {
it.path = it.name
}
}
into "$buildDir/text"
includeEmptyDirs = false
dependsOn downloadMetadata
}
// extract the processed webMAUS .TextGrid files to our build directory
task unpackTextGrids(type: Copy) {
from zipTree("$buildDir/metadata.zip"), {
include '**/textGrid/*.TextGrid'
eachFile {
it.path = it.name
}
}
into "$buildDir/TextGrid"
from zipTree("$buildDir/metadata.zip"), {
include '**/manuallyAdjustedTextGrid/*.TextGrid'
eachFile {
it.path = it.name
}
}
includeEmptyDirs = false
dependsOn downloadMetadata
}
// covert .TextGrids to .lab
task convertTextGrids {
ext.labDir = file("$buildDir/lab_maus")
dependsOn unpackTextGrids
dependsOn unpackText
outputs.dir labDir
doLast {
labDir.mkdirs()
def scriptFile = file("$temporaryDir/script.praat")
scriptFile.withWriter { script ->
fileTree(buildDir).include('TextGrid/*.TextGrid').each { textGridFile ->
def labFile = file("$labDir/${textGridFile.name - 'TextGrid' + 'lab'}")
script.println "Read from file... $textGridFile"
script.println "Extract tier... 3"
script.println "Save as Xwaves label file... $labFile"
//script.println "printline Wrote $labFile.name"
}
}
exec {
commandLine 'praat', '--run', scriptFile
}
}
}
// for maryTTS, some labels must be replaced
task remapLabels(type: Copy) {
from convertTextGrids.labDir
into "$buildDir/lab"
dependsOn convertTextGrids
filter {
def phoneMapping = [
'<p:>': '_',
'i:' : 'i',
'O:' : 'O',
'3`' : 'r=',
'Q' : 'A',
'R' : 'r',
'u:' : 'u',
'aI' : 'AI',
'eI' : 'EI'
]
def fields = it.tokenize()
if (fields.size() == 3) {
fields[-1] = phoneMapping[fields[-1]] ?: fields[-1]
}
fields.join(' ')
}
}
task copyDockerShellScriptToBuild(type: Copy) {
from "."
into "$buildDir"
include "dockerScript.sh"
}
task copyHTSGradleScriptToMaryBuild(type: Copy) {
from "."
into "$buildDir/mary/voice-endru/"
include "runHTSVoiceScript.txt"
rename ('runHTSVoiceScript.txt', 'build.gradle')
}
legacyInit {
dependsOn unpackWav, unpackText, remapLabels, copyDockerShellScriptToBuild, copyHTSGradleScriptToMaryBuild
}
// this is a fix for maryTTS
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.name == 'groovy-all') {
details.useTarget group: details.requested.group, name: details.requested.name, version: '2.4.7'
}
}
}
// this generates two files that can be modified in order to modify our voice's output
generateVoiceConfig {
afterEvaluate {
config << [
targetCostWeights: "jar:/marytts/voice/$voice.nameCamelCase/customTargetCostWeights.txt",
joinCostWeights : "jar:/marytts/voice/$voice.nameCamelCase/customJoinCostWeights.txt",
]
}
}
// this is the part where CrossValidation is programmed
// https://github.com/psibre/voice-ktn-build/blob/cross-validation/build.gradle
task generateCrossvalidationInputFiles {
def srcDir = file("$buildDir/text")
ext.destDir = file("$buildDir/crossvalidation/input")
inputs.files srcDir
outputs.dir destDir
doLast {
destDir.mkdirs()
fileTree(srcDir).include('*.txt').each { txtFile ->
def basename = txtFile.name - '.txt'
copy {
from 'src/templates'
include 'blacklist.xml'
expand([basename: basename, text: txtFile.text])
rename { basename + '.xml' }
into destDir
}
}
}
}
task synthesizeCrossValidationAudio {
dependsOn generateCrossvalidationInputFiles
ext.destDir = file("$buildDir/crossvalidation/output")
outputs.dir destDir
doLast {
destDir.mkdirs()
def mary = new marytts.client.RemoteMaryInterface()
mary.inputType = 'RAWMARYXML'
fileTree(generateCrossvalidationInputFiles.destDir).include('*.xml').each { xmlFile ->
def basename = xmlFile.name - '.xml'
def doc = MaryDomUtils.parseDocument(xmlFile)
mary.outputType = 'AUDIO'
def audio = mary.generateAudio(doc)
def samples = MaryAudioUtils.getSamplesAsDoubleArray(audio)
def wavFile = file("$destDir/${basename}.wav")
MaryAudioUtils.writeWavFile(samples, wavFile.path, audio.format)
logger.lifecycle "Wrote $wavFile"
def labFile = file("$destDir/${basename}.lab")
mary.outputType = 'REALISED_DURATIONS'
labFile.text = mary.generateText(doc)
logger.lifecycle "Wrote $labFile"
}
}
}
task copyCrossValidationReferenceData(type: Copy) {
dependsOn synthesizeCrossValidationAudio
from "$buildDir/wav", "$buildDir/lab"
into "$buildDir/crossvalidation/reference"
}
task runCrossValidation(type: JavaExec) {
dependsOn copyCrossValidationReferenceData
def allophonesFile = file("$buildDir/crossvalidation/allophones.en_US.xml")
classpath configurations.runtime
main 'marytts.signalproc.analysis.distance.RmsLsfDistortionComputer'
systemProperties = [allophoneset: allophonesFile.path]
args copyCrossValidationReferenceData.destinationDir, synthesizeCrossValidationAudio.destDir
doFirst {
download {
src 'https://raw.githubusercontent.com/marytts/marytts-lexicon-en_US-cmudict/master/modules/en/us/lexicon/allophones.en_US.xml'
dest allophonesFile
overwrite false
}
}
}