Bundle mission speech with an admin mute option and fix live audio downloads

This commit is contained in:
2026-10-15 16:53:39 +02:00
parent 07c4d70de5
commit 009b2fb591
181 changed files with 19248 additions and 103 deletions
+28 -4
View File
@@ -25,6 +25,9 @@ WELCOME = ("Welcome to Escape Reintroduced. Work together, stay alert, "
"and find your way off the island. Good luck.")
ENDPOINT = "https://texttospeech.googleapis.com/v1/text:synthesize"
MAX_AUDIO = 2 * 1024 * 1024
# Enfusion rejects REST responses >= 1 MB. Keep each JSON/base64 response well
# below that ceiling; this is transport slicing, not audio recompression.
VOICE_CHUNK = 262144
VETERAN_PROMPT = ("Speak as a fictional older war veteran, about sixty-five: a weathered, "
"slightly gravelly male voice, calm authority and dry warmth. "
"A concise field briefing to fellow soldiers, not a movie trailer. "
@@ -251,20 +254,41 @@ def handler_for(data, briefings=None):
print("TTS request completed (200)", flush=True)
def do_GET(self):
match = re.fullmatch(r"/clips/([0-9a-f]{64})\.b64", self.path)
url = urlsplit(self.path)
match = re.fullmatch(r"/clips/([0-9a-f]{64})\.b64", url.path)
if not match and url.path not in ("/welcome.wav", "/welcome.b64"):
self.send_error(404)
return
part = None
if url.query:
query = re.fullmatch(r"part=([0-9]{1,2})", url.query)
if not query or not url.path.endswith(".b64"):
self.send_error(400)
return
part = int(query[1])
if match and briefings:
try:
payload = base64.b64encode(briefings.read(match[1]))
except (OSError, ValueError):
self.send_error(404)
return
elif self.path in ("/welcome.wav", "/welcome.b64"):
payload = encoded if self.path == "/welcome.b64" else data
elif url.path in ("/welcome.wav", "/welcome.b64"):
payload = encoded if url.path == "/welcome.b64" else data
else:
self.send_error(404)
return
content_type = "text/plain" if url.path.endswith(".b64") else "audio/wav"
if part is not None:
offset = part * VOICE_CHUNK
if offset >= len(payload):
self.send_error(416)
return
payload = json.dumps({"offset": offset, "total": len(payload),
"data": payload[offset:offset + VOICE_CHUNK].decode("ascii")},
separators=(",", ":")).encode("ascii")
content_type = "application/json"
self.send_response(200)
self.send_header("Content-Type", "text/plain" if self.path.endswith(".b64") else "audio/wav")
self.send_header("Content-Type", content_type)
self.send_header("Content-Length", str(len(payload)))
self.end_headers()
self.wfile.write(payload)