main pita/uxn12 / etc / ext / festival.tal
 1( festival.tal )
 2( )
 3( sends text from stdin to the festival text-to-speech program )
 4( )
 5( requires festival: apt install festival )
 6
 7|00 @System
 8    |00 &vector $2
 9    |02 &expansion $2
10    |04 &title $2
11    |06 &metadata $2
12    |08 &r $2
13    |0a &g $2
14    |0c &b $2
15    |0e &debug $1
16    |0f &exit $1
17
18@Console
19    |10 &vector $2 ( called when input is ready )
20    |12 &read $1 ( read an input byte, e.g. from stdin )
21    ( 13 - 14 padding )
22    |15 &live $1 ( subprocess: 01 alive, ff dead, 00 not running )
23    |15 &exit $1 ( subprocess: exit code if dead )
24    |17 &type $1 ( input type: 01 stdin, 02 arg, 03 end of arg, 04 end of args )
25    |18 &write $1 ( byte to write to stdout )
26    |19 &error $1 ( byte to write to stderr )
27    ( 1a - 1b padding )
28    |1c &addr $2 ( subprocess: addr of string to run with /bin/sh -c )
29    |1e &mode $1 ( mode bits: 01 write stdin, 02 read stdout, 04 read stderr, 08 kill only )
30    |1f &exec $1 ( subprocess: run command )
31
32@Screen
33    |20 &vector $2
34    |22 &width $2
35    |24 &height $2
36    |26 &auto $1
37    ( 27 padding )
38    |28 &x $2
39    |2a &y $2
40    |2c &addr $2
41    |2e &pixel $1
42    |2f &sprite $1
43
44|0100
45    ( poll child process using the screen vector )
46    ;on-refresh .Screen/vector DEO2
47
48    ( set up festival child proces )
49    ;cmd .Console/addr DEO2
50    #07 .Console/mode DEO
51    #01 .Console/exec DEO
52
53    ( say some things, then quit festival and exit )
54    ;phrase1 print
55    ;phrase2 print
56    ;quit print
57    BRK
58
59( print a string to stdout )
60@print
61    LDAk ?{ POP2 JMP2r } LDAk .Console/write DEO INC2 !print
62
63( exit the ROM once festival exits )
64( we need to wait until it is done talking, which is why we don't exit earlier. )
65@on-refresh
66    .Console/live DEI #ff NEQ ?{ #80 .System/exit DEO } BRK
67
68@cmd
69    "festival 20 "--interactive 00
70
71@phrase1
72    28 "SayText 20 22 "This 20 "is 20 "a 20 "U.X.N 20 "text-to-speech 20 "demo. 22 29 0a 00
73
74@phrase2
75    28 "SayText 20 22 "If 20 "this 20 "were 20 "a 20 "real 20 "program ", 20 "interaction 20 "would 20 "occur. 22 29 0a 00
76
77@quit
78    28 "quit 29 0a 00