-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {choc, set_content, DOM, on} from "https://rosuav.github.io/choc/factory.js"; | ||
const {OPTGROUP, OPTION} = choc; //autoimport | ||
|
||
export function render(data) { | ||
set_content("#tts_voice", data.voices.map(([label, voices]) => | ||
OPTGROUP({label}, voices.map(v => OPTION({value: v.selector}, v.desc))) | ||
)); | ||
} | ||
|
||
export function sockmsg_speak(msg) { | ||
DOM("#player").src = msg.tts; | ||
DOM("#player").play(); | ||
} | ||
|
||
on("submit", "#send", e => { | ||
e.preventDefault(); | ||
ws_sync.send({cmd: "speak", text: DOM("#stuff").value, voice: DOM("#tts_voice").value}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
inherit http_websocket; | ||
inherit annotated; | ||
|
||
constant markdown = #"# TTS hack | ||
<audio controls id=player></audio> | ||
<label>Voice: <select id=tts_voice></select></label> | ||
<form id=send><label>Enter stuff: <input size=80 id=stuff></label> <button>Send</button></form> | ||
"; | ||
|
||
mapping(string:mixed) http_request(Protocols.HTTP.Server.Request req) { | ||
return render(req, (["vars": (["ws_group": req->variables->key || ""])])); | ||
} | ||
|
||
@retain: multiset tts_hack_valid_keys = (<>); | ||
string websocket_validate(mapping(string:mixed) conn, mapping(string:mixed) msg) { | ||
if (!tts_hack_valid_keys[msg->group]) return "Nope"; | ||
} | ||
|
||
mapping get_state(string group) { | ||
return (["voices": G->G->tts_config->avail_voices || ({ })]); | ||
} | ||
|
||
__async__ mapping|zero websocket_cmd_speak(mapping(string:mixed) conn, mapping(string:mixed) msg) { | ||
string text = msg->text; | ||
if (!text || text == "") return 0; | ||
object alertbox = G->G->websocket_types->chan_alertbox; | ||
text = await(alertbox->filter_bad_words(text, "replace")); | ||
string tts = await(alertbox->text_to_speech(text, msg->voice || "en-GB/en-GB-Standard-A/FEMALE", "tts_hack")); | ||
return (["cmd": "speak", "text": text, "tts": tts]); | ||
} | ||
|
||
protected void create(string name) {::create(name);} |