-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlilysong
149 lines (132 loc) · 3.8 KB
/
lilysong
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
#!/bin/bash
# Copyright (C) 2006 Brailcom, o.p.s.
#
# Author: Milan Zamazal <pdm@brailcom.org>
#
# COPYRIGHT NOTICE
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
set -e
usage () {
echo "usage: $0 [ -p PLAY-PROGRAM ] FILE.xml [ LANGUAGE-CODE-OR-VOICE [ SPEEDUP ] ]"
echo " $0 FILE.ly [ LANGUAGE-CODE-OR-VOICE ]"
echo " $0 --list-voices"
echo " $0 --list-languages"
exit 1
}
process_xml () {
local file="$1"
local voice="$2"
local speedup="$3"
local play="$4"
local wave="${file%xml}wav"
local tmpwave="$wave.tmp.$$"
local tmpxml="$file.tmp.$$"
local coding
trap "rm -f '$tmpwave' '$tmpxml'" EXIT
if [ "$voice" = voice_czech_ph ]; then
coding=iso-8859-2
else
coding=iso-8859-1
fi
iconv -f utf-8 -t $coding -o "$tmpxml" "$file"
text2wave -eval "($voice)" -mode singing "$tmpxml" -o "$tmpwave"
if [ -n "$speedup" ] && [ $speedup -ne 1 ]; then
sox "$tmpwave" "$wave" speed $speedup
else
mv "$tmpwave" "$wave"
fi
echo "$wave created."
if [ -n "$play" ]; then
"$play" "$wave" >/dev/null
fi
}
process_ly () {
local lyfile="$1"
local voice="$2"
lilypond "$lyfile"
local xmlfile=$(ls -t $(dirname "$lyfile") | grep '\.xml$' | head -1)
if [ -z "$xmlfile" ]; then
echo "No XML file found."
exit 1
fi
speedup=$(awk '/^#\(set! song:\*base-octave-shift\* -?[0-9]+\)/ { shift=$3 } END { print exp(-shift) }' "$lyfile")
process_xml "$xmlfile" "$voice" $speedup
}
list_voices () {
festival --pipe <<EOF
(let ((voices (voice.list))
(print-voice (lambda (v) (format t "voice_%s\n" v))))
(mapcar print-voice voices)
(mapcar (lambda (v) (if (not (member v voices)) (print-voice v)))
(mapcar car Voice_descriptions)))
EOF
}
list_languages () {
festival --pipe <<EOF
(let ((languages '()))
(let ((voices (voice.list))
(print-language (lambda (v)
(let ((language (cadr (assoc 'language (cadr (voice.description v))))))
(if (and language (not (member language languages)))
(begin
(set! languages (cons language languages))
(print language)))))))
(mapcar print-language voices)
(mapcar (lambda (v) (if (not (member v voices)) (print-language v)))
(mapcar car Voice_descriptions))))
EOF
}
if [ "$1" = --help ]; then
usage
elif [ "$1" = --list-voices ]; then
list_voices
exit 0
elif [ "$1" = --list-languages ]; then
list_languages
exit 0
fi
play=""
if [ "$1" = "-p" ]; then
shift
play="$1"
shift
fi
file="$1"
voice="$2"
speedup="$3"
if [ $# -lt 1 ] || [ $# -gt 3 ]; then
usage
fi
if [ "${voice#voice_}" = "$voice" ]; then
candidates=$(echo "
(mapcar (lambda (v)
(if (eq (cadr (assoc 'language (cadr (voice.description v))))
'$voice)
(format t \"voice_%s\n\" v)))
(append (voice.list) (mapcar car Voice_descriptions)))" | \
festival --pipe)
carray=($candidates)
voice=${carray[0]}
fi
if [ "$file" = "${file%ly}" ]; then
process_xml "$file" "$voice" "$speedup" "$play"
else
if [ -n "$speedup" ]; then
usage
fi
process_ly "$file" "$voice"
fi
exit 0