| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>FlightGear: Festival Voice Interface</title> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| 6 | </head> |
| 7 | |
| 8 | <body> |
| 9 | |
| 10 | |
| 11 | <h1>FlightGear: Festival Voice Interface</h1> |
| 12 | |
| 13 | This page describes how to use FlightGear's voice interface to the Festival speech synthesis system, so that |
| 14 | ATC, Pilot, etc. messages can be made audible. These messages are normally only displayed on top of the screen. |
| 15 | A raw socket mode allows to send the messages to arbitrary servers. |
| 16 | |
| 17 | |
| 18 | <h2>Quick instructions (assuming that you have Festival installed)</h2> |
| 19 | |
| 20 | <blockquote><pre> |
| 21 | $ festival --server & |
| 22 | $ fgfs --aircraft=j3cub --airport=KSQL --prop:/sim/sound/voices/enabled=true</pre></blockquote> |
| 23 | |
| 24 | Now, in FlightGear, enable ATC (in the menu under "ATC"->"Options"), press the '-key (apostrophe key) and |
| 25 | send a message to the ATC. Hear "your" voice, that of the ATC, and some time later that of AI-planes. |
| 26 | |
| 27 | |
| 28 | |
| 29 | <h2>Installing the Festival system</h2> |
| 30 | |
| 31 | <ul> |
| 32 | <li> |
| 33 | Make sure Festival is installed, or download it from here: |
| 34 | <a href="http://www.cstr.ed.ac.uk/projects/festival/">http://www.cstr.ed.ac.uk/projects/festival/</a> |
| 35 | </li><li> |
| 36 | Check if Festival works. Only the relevant lines are shown here. Note the parentheses! |
| 37 | <blockquote><pre> |
| 38 | $ festival |
| 39 | festival> (SayText "FlightGear") |
| 40 | festival> (quit)</pre></blockquote> |
| 41 | </li><li> |
| 42 | Check if MBROLA is installed, or download it from here: |
| 43 | <a href="http://tcts.fpms.ac.be/synthesis/mbrola/">http://tcts.fpms.ac.be/synthesis/mbrola/</a> -> "Downloads" |
| 44 | -> "MBROLA binary and voices" (link at the bottom; hard to find). Choose the binary for your platform. |
| 45 | Unfortunately, there's no source code available. If you don't like that, then you can skip the whole MBROLA |
| 46 | setup. But then you can't use the more realistic voices. You can also install further MBROLA voices from |
| 47 | this page. (See below) |
| 48 | </li><li> |
| 49 | Run MBROLA and marvel at the help screen. That's just to check if it's in the path and executable. |
| 50 | <blockquote><pre> |
| 51 | $ mbrola -h</pre></blockquote> |
| 52 | </li> |
| 53 | </ul> |
| 54 | |
| 55 | |
| 56 | <h2>Installing more voices</h2> |
| 57 | |
| 58 | I'm afraid this is a bit tedious. You can skip it if you are happy with the default voice. First find the |
| 59 | Festival data directory. All Festival data goes to a common file tree, like in FlightGear. This can be |
| 60 | <tt>/usr/local/share/festival/</tt> on Unices. We'll call that directory <tt>$FESTIVAL</tt> for now. |
| 61 | |
| 62 | <ul> |
| 63 | <li> |
| 64 | Check which voices are available. You can test them by prepending <tt>voice_</tt>: |
| 65 | <blockquote><pre> |
| 66 | $ festival |
| 67 | festival> (print (mapcar (lambda (pair) (car pair)) voice-locations)) |
| 68 | (kal_diphone rab_diphone don_diphone us1_mbrola us2_mbrola us3_mbrola en1_mbrola) |
| 69 | nil |
| 70 | festival> (voice_us3_mbrola) |
| 71 | festival> (SayText "I've got a nice voice.") |
| 72 | festival> (quit)</pre></blockquote> |
| 73 | </li><li> |
| 74 | Festival voices and MBROLA wrappers can be downloaded here: |
| 75 | <a href="http://festvox.org/packed/festival/1.95/">http://festvox.org/packed/festival/1.95/</a> |
| 76 | The "don_diphone" voice isn't the best, but it's comparatively small and well suited for "ai-planes". |
| 77 | If you install it, it should end up as directory <tt>$FESTIVAL/voices/english/don_diphone/</tt>. You also need |
| 78 | to install "festlex_OALD.tar.gz" for it as <tt>$FESTIVAL/dicts/oald/</tt> and run the Makefile in this |
| 79 | directory. (You may have to add "<tt>--heap 10000000</tt>" to the festival command arguments in the Makefile.) |
| 80 | </li><li> |
| 81 | Quite good voices are "us2_mbrola", "us3_mbrola", and "en1_mbrola". For these you need to install |
| 82 | MBROLA (see above) as well as these wrappers: <tt>festvox_us2.tar.gz</tt>, <tt>festvox_us3.tar.gz</tt>, |
| 83 | and <tt>festvox_en1.tar.gz</tt>. They create directories <tt>$FESTIVAL/voices/english/us2_mbrola/</tt> etc. |
| 84 | The voice <em>data</em>, however, has to be downloaded separately from another site: |
| 85 | </li><li> |
| 86 | MBROLA voices can be downloaded from the MBROLA download page (see above). You want the |
| 87 | voices labeled "us2" and "us3". Unpack them in the directories that the wrappers have created: |
| 88 | <tt>$FESTIVAL/voices/english/us2_mbrola/</tt> and likewise for "us3" and "en1". |
| 89 | </li> |
| 90 | </ul> |
| 91 | |
| 92 | |
| 93 | <h2>Running FlightGear with voice support</h2> |
| 94 | |
| 95 | <ul> |
| 96 | <li>First start the festival server: |
| 97 | <blockquote><pre> |
| 98 | $ festival --server</pre></blockquote> |
| 99 | </li><li> |
| 100 | Start FlightGear with enabled voice subsystem, let's say with |
| 101 | <blockquote><pre> |
| 102 | $ fgfs --aircraft=j3cub --airport=KSQL --prop:/sim/sound/voices/enabled=true</pre></blockquote> |
| 103 | Of course, you can put this option into your personal configuration file. This doesn't mean that |
| 104 | you then <em>always</em> have to use FlightGear together with Festival. You'll just get a few |
| 105 | error messages in the terminal window, but that's it. Note that you can currently <em>not</em> |
| 106 | enable the voice subsystem at runtime! |
| 107 | </li><li> |
| 108 | Open the property browser to <tt>/sim/sound/voices/voice[0]/</tt> and write some text to the |
| 109 | <tt>text</tt> property. You should now hear this spoken with the default voice ("voice_kal_diphone"). |
| 110 | You can try the same with <tt>voice[1]/</tt> etc. and should hear different voices if they |
| 111 | are installed, or the default voice again otherwise. |
| 112 | </li><li> |
| 113 | Contact the KSFO ATC via '-key dialog (apostrophe key). You should hear "your" voice first (and see the |
| 114 | text in yellow color on top of the screen), then you should hear ATC answer with a different voice (and see |
| 115 | it in light-green color). |
| 116 | </li><li> |
| 117 | You can edit the voice parameters in the <tt>preferences.xml</tt> file, and select different |
| 118 | screen colors and voice assignments in <tt>$FG_ROOT/Nasal/voice.nas</tt>. The messages aren't written |
| 119 | to the respective <tt>/sim/sound/voices/voice[*]/text</tt> properties directly, but rather to aliases |
| 120 | <tt>/sim/sound/voices/{atc,approach,ground,pilot,ai-plane}</tt>. (BTW: I've never heard anything from |
| 121 | <tt>ground</tt> and <tt>approach</tt> yet.) |
| 122 | </li> |
| 123 | </ul> |
| 124 | |
| 125 | |
| 126 | |
| 127 | <h2>Configuration & Internals</h2> |
| 128 | |
| 129 | The <em>voice</em> subsystem only offers the common subsystem functions to the rest of FlightGear. |
| 130 | There's no built-in function to let it send data to the socket. The only way is to write to the |
| 131 | respective speech properties. The number of available voices, or rather "channels", isn't hard-coded. |
| 132 | It's the number of <voice> groups in "/sim/sound/voices" that decides how many channels should be |
| 133 | opened. This is a typical setting of interface properties, whereby the aliases at the end have |
| 134 | nothing to do with the subsystem, but are handy shortcuts: |
| 135 | |
| 136 | <blockquote><pre> |
| 137 | <sim> |
| 138 | <voices> |
| 139 | <host type="string">localhost</host> |
| 140 | <port type="string">1314</port> |
| 141 | <enabled type="bool">false</enabled> |
| 142 | |
| 143 | <voice> |
| 144 | <desc>Pilot</desc> |
| 145 | <text type="string"></text> |
| 146 | <volume type="double">1.0</volume> |
| 147 | <pitch type="double">100.0</pitch> |
| 148 | <speed type="double">1.0</speed> |
| 149 | <preamble type="string">(voice_us3_mbrola)</preamble> |
| 150 | <festival type="bool">true</festival> |
| 151 | </voice> |
| 152 | |
| 153 | <voice> |
| 154 | ... |
| 155 | </voice> |
| 156 | |
| 157 | <!-- handy aliases, not part of the interface: --> |
| 158 | |
| 159 | <atc alias="/sim/sound/voices/voice[0]/text"/> |
| 160 | <approach alias="/sim/sound/voices/voice[0]/text"/> |
| 161 | <ground alias="/sim/sound/voices/voice[0]/text"/> |
| 162 | <pilot alias="/sim/sound/voices/voice[1]/text"/> |
| 163 | <copilot alias="/sim/sound/voices/voice[2]/text"/> |
| 164 | <ai-plane alias="/sim/sound/voices/voice[3]/text"/> |
| 165 | </voices> |
| 166 | </sim> |
| 167 | </pre></blockquote> |
| 168 | |
| 169 | The <enabled> property decides at init time whether the subsystem should |
| 170 | be activated or not. There's currently no way to change this at runtime. |
| 171 | |
| 172 | Each <voice> group defines one channel. <text> is the output |
| 173 | property. Every value that's written to it will be spoken by this channel. |
| 174 | If <festival> is true, then the channel will set up <pitch> and |
| 175 | <speed> (<volume> does currently not work and has to be <tt>1</tt>), |
| 176 | and puts Festival markup around the text. If <festival> is false, |
| 177 | then all text is written verbatim to the socket. <preamble> is always |
| 178 | written to the socket once as last step of the socket creation. In "festival" |
| 179 | mode it's used to set the voice, while in raw mode it could be used to identify |
| 180 | the channel (assuming that the server knows what to do with it). |
| 181 | |
| 182 | |
| 183 | |
| 184 | <h2>Usage</h2> |
| 185 | |
| 186 | The design principle is that message generators (e.g. the ATC subsystem) write |
| 187 | to a message property (e.g. <tt>/sim/messages/pilot</tt>). A listener ($FG_ROOT/Nasal/screen.nas) |
| 188 | watches this property and decides what to do with it. For pilot and ATC it writes the message |
| 189 | to the screen.log and copies it to the <tt>/sim/sound/voices/pilot</tt> property. This |
| 190 | is an alias to the real voice channel <tt>/sim/sound/voices/voice[1]/text</tt>. |
| 191 | This allows the most control and makes all steps user-configurable from Nasal |
| 192 | scripts. Message generator should <em>not</em> write to the voice's <text> |
| 193 | property directly, and only to the <tt>/sim/sound/voices/*</tt> aliases if a |
| 194 | message should not be displayed by the system. |
| 195 | |
| 196 | |
| 197 | |
| 198 | <h2>Backward compatibility</h2> |
| 199 | |
| 200 | The new voice subsystem is functionally compatible with the old one that |
| 201 | was part of the ATC subsystem. You just need to turn the <festival> |
| 202 | bool properties off and set the server address correctly. This sends only |
| 203 | the messages without any Festival syntax added: |
| 204 | |
| 205 | <blockquote><pre> |
| 206 | <sim> |
| 207 | <voices> |
| 208 | <host type="string">192.168.2.15</host> |
| 209 | <port type="string">7100</port> |
| 210 | <enabled type="bool">true</enabled> |
| 211 | <voice> |
| 212 | <desc>ATC/Approach/Ground</desc> |
| 213 | <text type="string"></text> |
| 214 | <preamble type="string">ATC</preamble> |
| 215 | <festival type="bool">false</festival> |
| 216 | </voice> |
| 217 | <voice> |
| 218 | <desc>Pilot</desc> |
| 219 | <text type="string"></text> |
| 220 | <preamble type="string">Pilot</preamble> |
| 221 | <festival type="bool">false</festival> |
| 222 | </voice> |
| 223 | ... |
| 224 | </voices> |
| 225 | </sim> |
| 226 | </pre></blockquote> |
| 227 | |
| 228 | <volume>, <pitch>, and <speed> have no meaning and can |
| 229 | be left away. Note that also in this mode the preamble gets sent first. |
| 230 | It can be used to identify the channel. Of course, all messages could be |
| 231 | sent to just one channel, though. |
| 232 | |
| 233 | |
| 234 | |
| 235 | <h2>Multichannel server</h2> |
| 236 | |
| 237 | Raw mode does, of course, require a different server than Festival. Here's |
| 238 | a small Perl example for a multichannel server. Note how the <preamble> |
| 239 | is used as channel identification: |
| 240 | |
| 241 | |
| 242 | <blockquote><pre> |
| 243 | #!/usr/bin/perl -Tw |
| 244 | # License: GPL V2 |
| 245 | # Modified after Example from perlipc.pod ($ man perlipc) |
| 246 | |
| 247 | use strict; |
| 248 | BEGIN { |
| 249 | $ENV{PATH} = '/usr/ucb:/bin'; |
| 250 | } |
| 251 | |
| 252 | use Socket; |
| 253 | use Carp; |
| 254 | my $EOL = "\015\012"; |
| 255 | |
| 256 | sub spawn; # forward declaration |
| 257 | sub logmsg { |
| 258 | print "$0 $$: @_ at ", scalar localtime, "\n"; |
| 259 | } |
| 260 | |
| 261 | |
| 262 | my $port = shift || 1314; |
| 263 | my $proto = getprotobyname('tcp'); |
| 264 | |
| 265 | |
| 266 | ($port) = $port =~ /^(\d+)$/ or die "invalid port"; |
| 267 | |
| 268 | |
| 269 | socket(Server, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; |
| 270 | setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) || die "setsockopt: $!"; |
| 271 | bind(Server, sockaddr_in($port, INADDR_ANY)) || die "bind: $!"; |
| 272 | listen(Server,SOMAXCONN) || die "listen: $!"; |
| 273 | |
| 274 | |
| 275 | logmsg "server started on port $port"; |
| 276 | |
| 277 | |
| 278 | my $waitedpid = 0; |
| 279 | my $paddr; |
| 280 | |
| 281 | use POSIX ":sys_wait_h"; |
| 282 | sub REAPER { |
| 283 | my $child; |
| 284 | while (($waitedpid = waitpid(-1,WNOHANG)) > 0) { |
| 285 | logmsg "reaped $waitedpid" . ($? ? " with exit $?" : ''); |
| 286 | } |
| 287 | $SIG{CHLD} = \&REAPER; # loathe sysV |
| 288 | } |
| 289 | |
| 290 | |
| 291 | $SIG{CHLD} = \&REAPER; |
| 292 | |
| 293 | for ($waitedpid = 0; |
| 294 | ($paddr = accept(Client,Server)) || $waitedpid; |
| 295 | $waitedpid = 0, close Client) { |
| 296 | next if $waitedpid and not $paddr; |
| 297 | my($port,$iaddr) = sockaddr_in ($paddr); |
| 298 | my $name = gethostbyaddr($iaddr,AF_INET); |
| 299 | |
| 300 | logmsg "connection from $name [", inet_ntoa($iaddr), "] at port $port"; |
| 301 | |
| 302 | spawn sub { |
| 303 | $|=1; |
| 304 | print "Hello there, $name, it's now ", scalar localtime, $EOL; |
| 305 | exec '/usr/bin/fortune' # XXX: `wrong' line terminators |
| 306 | or confess "can't exec fortune: $!"; |
| 307 | }; |
| 308 | } |
| 309 | |
| 310 | |
| 311 | sub spawn |
| 312 | { |
| 313 | my $coderef = shift; |
| 314 | |
| 315 | unless (@_ == 0 && $coderef && ref($coderef) eq 'CODE') { |
| 316 | confess "usage: spawn CODEREF"; |
| 317 | } |
| 318 | |
| 319 | my $pid; |
| 320 | if (!defined($pid = fork)) { |
| 321 | logmsg "cannot fork: $!"; |
| 322 | return; |
| 323 | } elsif ($pid) { |
| 324 | logmsg "creating child $pid"; |
| 325 | return; # I'm the parent |
| 326 | } |
| 327 | # else I'm the child -- go spawn |
| 328 | |
| 329 | # print header |
| 330 | my $id; |
| 331 | while (<Client>) { |
| 332 | s/^\s+//; |
| 333 | s/\s+$//; |
| 334 | |
| 335 | # first line is voice channel id = "<preamble>" |
| 336 | if (not defined $id) { |
| 337 | $id = $_; |
| 338 | next; |
| 339 | } |
| 340 | |
| 341 | print "\033[32m$id: \033[m$_\n"; |
| 342 | last unless /\S/; |
| 343 | } |
| 344 | |
| 345 | open(STDIN, "<&Client") || die "can't dup client to stdin"; |
| 346 | open(STDOUT, ">&Client") || die "can't dup client to stdout"; |
| 347 | ## open(STDERR, ">&STDOUT") || die "can't dup stdout to stderr"; |
| 348 | exit &$coderef(); |
| 349 | } |
| 350 | </pre></blockquote> |
| 351 | |
| 352 | </body> |
| 353 | </html> |
| 354 |