-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_dita2audiobook.xml
executable file
·312 lines (279 loc) · 8.87 KB
/
build_dita2audiobook.xml
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<?xml version="1.0" encoding="UTF-8"?>
<!--ant-->
<!--
This file is part of the DITA-OT Audiobook Plug-in project.
See the accompanying LICENSE file for applicable licenses.
-->
<project
xmlns:dita="http://dita-ot.sourceforge.net"
name="fox.jason.audiobook"
xmlns:if="ant:if"
>
<!--
Setting up SSML processing. Sets up ANT variable overrides.
-->
<target name="audiobook.init">
<taskdef resource="fox/jason/audiobook/antlib.xml"/>
<property name="build-step.copy-image" value="false"/>
<property name="build-step.copy-flag" value="false"/>
<property name="out.ext" value="ssml"/>
</target>
<target
name="audiobook.services.init"
depends="audiobook.init, text-to-speech.init, ffmpeg.init"
>
<property name="ssml.output.dir" value="${dita.temp.dir}/ssml"/>
</target>
<!--
Setting up SSML processing. Sets up ANT variable overrides.
-->
<target name="ssml.init" depends="audiobook.init">
<property name="ssml.output.dir" value="${output.dir}"/>
</target>
<!--
Generate SSML files containing associated dublin core metadata
-->
<target
name="ssml.render"
description="Create Speech Synthesis Markup Language Files">
<pipeline message="Convert DITA topics to SSML files" taskname="gen-ssml">
<xslt
basedir="${dita.temp.dir}"
extension="ssml"
destdir="${ssml.output.dir}"
reloadstylesheet="${dita.ssml.reloadstylesheet}"
classpathref="dost.class.path"
style="${dita.plugin.fox.jason.audiobook.dir}/xsl/dita2ssml.xsl"
filenameparameter="FILENAME"
filedirparameter="FILEDIR"
>
<ditafileset format="dita" processingRole="normal"/>
<xmlcatalog refid="dita.catalog"/>
<param expression="${args.input}" name="SOURCE"/>
<param name="BASEDIR" expression="${dita.dir}"/>
<param name="OUTPUTDIR" expression="${dita.output.dir}"/>
<param name="defaultLanguage" expression="${default.language}"/>
</xslt>
</pipeline>
</target>
<!--
Setting up SSML to speech MP3 processing.
Currently using either IBM Watson or Microsoft Azure for processing
to MP3.
Ensure that Watson/Bing is available.
-->
<target name="text-to-speech.init">
<!-- Load Service URLs from command line -->
<property
name="watson.text-to-speech.url"
if:set="ssml.url"
value="${ssml.url}"
/>
<property name="watson.apikey" if:set="ssml.apikey" value="${ssml.apikey}"/>
<property name="bing.apikey" if:set="ssml.apikey" value="${ssml.apikey}"/>
<property
name="bing.text-to-speech.url"
if:set="ssml.url"
value="${ssml.url}"
/>
<property
name="bing.authentication.url"
if:set="ssml.authentication.url"
value="${ssml.authentication.url}"
/>
<property
name="bing.output.format"
if:set="ssml.output.format"
value="${ssml.output.format}"
/>
<property
name="custom.text-to-speech.url"
if:set="ssml.url"
value="${ssml.url}"
/>
<!-- Fallback - load Service URLs from properties file -->
<property
file="${dita.plugin.fox.jason.audiobook.dir}/cfg/configuration.properties"
/>
<!-- Set other ssml service defaults -->
<property name="ssml.service" value="watson"/>
<property name="ssml.gender" value="male"/>
<property
name="mp3.cover.art.image"
value="${dita.plugin.fox.jason.audiobook.dir}/resource/cover-art.png"
/>
<!-- Decide which service to use -->
<condition property="audiobook.bing">
<equals arg1="${ssml.service}" arg2="bing"/>
</condition>
<condition property="audiobook.watson">
<equals arg1="${ssml.service}" arg2="watson"/>
</condition>
<condition property="audiobook.dummy">
<equals arg1="${ssml.service}" arg2="dummy"/>
</condition>
<condition property="audiobook.custom">
<equals arg1="${ssml.service}" arg2="custom"/>
</condition>
<condition property="pm3.cover">
<equals arg1="${mp3.cover.art.add}" arg2="yes"/>
</condition>
<dita-ot-fail id="AUDI002F" if:set="audiobook.watson">
<condition>
<equals arg1="${watson.apikey}" arg2="XXX"/>
</condition>
</dita-ot-fail>
<dita-ot-fail id="AUDI003F" if:set="bing">
<condition>
<equals arg1="${bing.apikey}" arg2="XXX"/>
</condition>
</dita-ot-fail>
<bing-authorization if:set="audiobook.bing"/>
</target>
<!--
Generate MP3 files from SSML then create an id3v2 tag holding
the appropriate metadata and track info and add it to each of
the MP3 files
-->
<target name="mp3.render"
depends="ssml.render"
description="Create Speech MP3 files for each topic">
<property name="topic-list.txt" value="${dita.output.dir}/list.txt"/>
<!-- create track list -->
<xslt
in="${dita.temp.dir}${file.separator}${user.input.file}"
out="${topic-list.txt}"
style="${dita.plugin.fox.jason.audiobook.dir}/xsl/create-topic-list.xsl"
taskname="track-list"
>
<xmlcatalog refid="dita.catalog"/>
</xslt>
<ssml-to-mp3 dir="${dita.output.dir}" file="${topic-list.txt}"/>
<dita-ot-fail id="AUDI004F">
<condition>
<isset property="ssml.failed"/>
</condition>
</dita-ot-fail>
<!-- create SSML cache file -->
<property
name="ssml.cachefile"
value="${dita.output.dir}/cache.properties"
/>
<delete file="${ssml.cachefile}" quiet="true" failonerror="false"/>
<copy taskname="gen-cache" todir="${dita.temp.dir}/cachefiles">
<fileset dir="${ssml.output.dir}">
<include name="**/*.ssml"/>
<modified update="true">
<param name="cache.cachefile" value="${ssml.cachefile}"/>
<param name="algorithm.algorithm" value="MD5"/>
</modified>
</fileset>
</copy>
<replace file="${ssml.cachefile}" token="${ssml.output.dir}/" value=""/>
</target>
<!--
Ensure that ffmpeg is available.
-->
<target name="ffmpeg.init"
description="Ensure that ffmpeg is available">
<!-- For Unix run the FFmpeg executable-->
<exec
taskname="ffmpeg"
executable="ffmpeg"
osfamily="unix"
failonerror="false"
failifexecutionfails="false"
resultproperty="ffmpeg.result"
outputproperty="ffmpeg.out"
>
<arg value="-version"/>
</exec>
<!-- For Windows run FFmpeg from a DOS command -->
<exec
taskname="ffmpeg"
dir="${dita.dir}/bin"
executable="cmd"
osfamily="windows"
failonerror="false"
failifexecutionfails="false"
resultproperty="ffmpeg.result"
outputproperty="ffmpeg.out"
>
<arg value="/C"/>
<arg value="ffmpeg -version"/>
</exec>
<echo
level="verbose"
message="${line.separator}${ffmpeg.out}"
taskname="ffmpeg"
/>
<dita-ot-fail id="AUDI001F">
<condition>
<not>
<equals arg1="${ffmpeg.result}" arg2="0"/>
</not>
</condition>
</dita-ot-fail>
</target>
<!--
Process each MP3 file in turn and read the id3v2 tag for
timings and chapter names.
Then create chapters.txt and combine all MP3 files. The
overall metadata anc chapter info can be re-added into
an audiobook m4b file (along with a cover image)
-->
<target name="audiobook.render"
depends="ssml.render, mp3.render"
description="Merge MP3 files into an Audiobook">
<property name="audiobook.duration" value="0"/>
<property name="audiobook.format" value="m4a"/>
<basename
file="${args.input}"
property="audiobook.filename.root"
suffix=".ditamap"
/>
<tempfile
deleteonexit="true"
destdir="${dita.temp.dir}"
property="chapter.temp.file"
suffix=".txt"
/>
<echo file="${chapter.temp.file}" message=";FFMETADATA1"/>
<tempfile
deleteonexit="true"
destdir="${dita.temp.dir}"
property="metadata.temp.file"
suffix=".txt"
/>
<xslt
in="${dita.temp.dir}${file.separator}${user.input.file}"
out="${metadata.temp.file}"
style="${dita.plugin.fox.jason.audiobook.dir}/xsl/ditamap-id3v2tag.xsl"
>
<xmlcatalog refid="dita.catalog"/>
</xslt>
<create-chapters dir="${dita.output.dir}" file="${topic-list.txt}"/>
<merge-audiobook
chapters="${chapter.temp.file}"
file="${topic-list.txt}"
dir="${dita.output.dir}"
metadata="${metadata.temp.file}"
output="${audiobook.filename.root}.${audiobook.format}"
/>
</target>
<!--
ANT targets to create SSML, MP3 and audiobook files
-->
<target
name="dita2ssml"
depends="build-init, ssml.init, preprocess2, ssml.render"
/>
<target
name="dita2mp3"
depends="build-init, audiobook.services.init, preprocess2, mp3.render"
/>
<target
name="dita2audiobook"
depends="build-init, audiobook.services.init, preprocess2, audiobook.render"
/>
</project>