|
| 1 | +<?xml version="1.0" encoding="iso-8859-1"?> |
| 2 | +<!DOCTYPE muclient> |
| 3 | + |
| 4 | +<muclient> |
| 5 | +<plugin |
| 6 | + name="Sapi_speaker" |
| 7 | + author="Nick Gammon" |
| 8 | + id="463242566069ebfd1b379ec1" |
| 9 | + language="Lua" |
| 10 | + purpose="Speaks incoming text using SAPI." |
| 11 | + date_written="2010-09-01" |
| 12 | + requires="3.45" |
| 13 | + version="1.0" |
| 14 | + > |
| 15 | + |
| 16 | +<description trim="y"> |
| 17 | +Type: |
| 18 | + |
| 19 | + sapi on --> turn on speaking (the default) |
| 20 | + sapi off --> turn off speaking of MUD output |
| 21 | + sapi skip --> skips one sentence in output stream |
| 22 | + |
| 23 | +Other scripts can speak stuff by doing: |
| 24 | + |
| 25 | + CallPlugin ("463242566069ebfd1b379ec1", "say", "What to say") |
| 26 | + |
| 27 | +</description> |
| 28 | +</plugin> |
| 29 | + |
| 30 | +<!-- Triggers --> |
| 31 | +<aliases> |
| 32 | + <alias |
| 33 | + match="sapi on" |
| 34 | + enabled="n" |
| 35 | + omit_from_command_history="y" |
| 36 | + omit_from_log="y" |
| 37 | + omit_from_output="y" |
| 38 | + script="speak_on" |
| 39 | + sequence="100" |
| 40 | + group="speech" |
| 41 | + > |
| 42 | + </alias> |
| 43 | + |
| 44 | + <alias |
| 45 | + match="sapi off" |
| 46 | + enabled="n" |
| 47 | + omit_from_command_history="y" |
| 48 | + omit_from_log="y" |
| 49 | + omit_from_output="y" |
| 50 | + script="speak_off" |
| 51 | + sequence="100" |
| 52 | + group="speech" |
| 53 | + > |
| 54 | + </alias> |
| 55 | + |
| 56 | + <alias |
| 57 | + match="sapi skip" |
| 58 | + enabled="n" |
| 59 | + omit_from_log="y" |
| 60 | + omit_from_output="y" |
| 61 | + script="speak_skip" |
| 62 | + sequence="100" |
| 63 | + group="speech" |
| 64 | + > |
| 65 | + </alias> |
| 66 | + |
| 67 | +</aliases> |
| 68 | + |
| 69 | +<triggers> |
| 70 | +</triggers> |
| 71 | + |
| 72 | +<!-- Script --> |
| 73 | + |
| 74 | + |
| 75 | +<script> |
| 76 | +<![CDATA[ |
| 77 | +
|
| 78 | +-- turn on speaking |
| 79 | +function speak_on (name, line, wildcards) |
| 80 | + speak = true |
| 81 | + talk:Speak ("Sapi auto speak now on.", 1) |
| 82 | +end -- function speak_on |
| 83 | +
|
| 84 | +-- turn off speaking |
| 85 | +function speak_off (name, line, wildcards) |
| 86 | + speak = false |
| 87 | + talk:Speak ("Sapi auto speak now off.",1) |
| 88 | +end -- function speak_off |
| 89 | +
|
| 90 | +-- skip a sentence |
| 91 | +function speak_skip (name, line, wildcards) |
| 92 | + talk:Skip ("Sentence", 1) |
| 93 | +end -- function speak_skip |
| 94 | +
|
| 95 | +-- installation |
| 96 | +function OnPluginInstall () |
| 97 | +
|
| 98 | + -- load Lua COM |
| 99 | + assert (package.loadlib ("luacom.dll", "luacom_open")) () |
| 100 | + |
| 101 | + -- Instantiate a SAPI voice obejct |
| 102 | + talk = assert (luacom.CreateObject ("SAPI.SpVoice"), "cannot open SAPI") |
| 103 | + |
| 104 | + -- Method call |
| 105 | + talk:Speak ("SAPI Plugin installed and is ready.", 1) |
| 106 | +
|
| 107 | + speak = true |
| 108 | + EnableGroup ("speech", true) |
| 109 | + |
| 110 | +end -- function OnPluginInstall |
| 111 | +
|
| 112 | +-- here to draw the screen |
| 113 | +function OnPluginScreendraw (t, log, line) |
| 114 | +
|
| 115 | + -- check loaded |
| 116 | + if not talk then |
| 117 | + return |
| 118 | + end -- if not installed |
| 119 | +
|
| 120 | + if (t == 0 or t == 1) and speak then |
| 121 | + talk:Speak (line, 1) |
| 122 | + end -- if |
| 123 | + |
| 124 | +end -- function |
| 125 | + |
| 126 | +-- Speak from other scripts |
| 127 | +-- eg. CallPlugin ("463242566069ebfd1b379ec1", "say", "What to say") |
| 128 | +
|
| 129 | +function say (what) |
| 130 | +
|
| 131 | + -- check loaded |
| 132 | + if not talk then |
| 133 | + return false -- failure |
| 134 | + end -- if not installed |
| 135 | +
|
| 136 | + talk:Speak (what, 1) |
| 137 | + |
| 138 | + return true -- OK |
| 139 | +end -- function say |
| 140 | +
|
| 141 | +]]> |
| 142 | +</script> |
| 143 | + |
| 144 | +</muclient> |
0 commit comments