Skip to content

Commit

Permalink
Minot QOL improvements to TTS hack.
Browse files Browse the repository at this point in the history
It'll remember the last-used voice for next time, and also clear out
the input when you hit Enter.
  • Loading branch information
Rosuav committed Jan 5, 2025
1 parent fe743f1 commit 7b78266
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions httpstatic/tts_hack.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import {choc, set_content, DOM, on} from "https://rosuav.github.io/choc/factory.js";
const {OPTGROUP, OPTION} = choc; //autoimport

let have_set_voice = false;
export function render(data) {
set_content("#tts_voice", data.voices.map(([label, voices]) =>
OPTGROUP({label}, voices.map(v => OPTION({value: v.selector}, v.desc)))
));
if (!have_set_voice) {
have_set_voice = true; //Even if there's nothing in localStorage, only do this once
const v = localStorage.getItem("ttshack_voice");
if (v && v !== "") DOM("#tts_voice").value = v;
}
}

export function sockmsg_speak(msg) {
Expand All @@ -15,4 +21,6 @@ export function sockmsg_speak(msg) {
on("submit", "#send", e => {
e.preventDefault();
ws_sync.send({cmd: "speak", text: DOM("#stuff").value, voice: DOM("#tts_voice").value});
DOM("#stuff").value = "";
localStorage.setItem("ttshack_voice", DOM("#tts_voice").value);
});
1 change: 1 addition & 0 deletions modules/http/tts_hack.pike
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ __async__ mapping|zero websocket_cmd_speak(mapping(string:mixed) conn, mapping(s
if (!text || text == "") return 0;
object alertbox = G->G->websocket_types->chan_alertbox;
text = await(alertbox->filter_bad_words(text, "replace"));
werror("TTS Hack %O -> %O\n", msg->voice, msg->text);
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]);
}
Expand Down

0 comments on commit 7b78266

Please sign in to comment.