From 7b782668ae7a93aa054f3a2286255a534d1b0038 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Mon, 6 Jan 2025 07:42:38 +1100 Subject: [PATCH] Minot QOL improvements to TTS hack. It'll remember the last-used voice for next time, and also clear out the input when you hit Enter. --- httpstatic/tts_hack.js | 8 ++++++++ modules/http/tts_hack.pike | 1 + 2 files changed, 9 insertions(+) diff --git a/httpstatic/tts_hack.js b/httpstatic/tts_hack.js index f4723ebe..248c7262 100644 --- a/httpstatic/tts_hack.js +++ b/httpstatic/tts_hack.js @@ -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) { @@ -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); }); diff --git a/modules/http/tts_hack.pike b/modules/http/tts_hack.pike index d6dcbb5e..3a837f66 100644 --- a/modules/http/tts_hack.pike +++ b/modules/http/tts_hack.pike @@ -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]); }