Text-to-Speech
ONNX
Vietnamese
vietnamese
flow-matching
webgpu
on-device
File size: 1,825 Bytes
531d4d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Serve the Trà Đá web demo locally: python web/serve.py [port] [host]  ->  http://localhost:8000
Serves the repo root (the page loads ../onnx, ../voices, ../config.json) with the COOP/COEP headers that
multi-threaded WASM needs and the right MIME types. WebGPU and the microphone need localhost or https."""
import http.server, os, socketserver, sys
PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
HOST = sys.argv[2] if len(sys.argv) > 2 else "127.0.0.1"
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))


class H(http.server.SimpleHTTPRequestHandler):
    extensions_map = {**http.server.SimpleHTTPRequestHandler.extensions_map, ".mjs": "text/javascript", ".js": "text/javascript",
                      ".wasm": "application/wasm", ".onnx": "application/octet-stream", ".json": "application/json", ".wav": "audio/wav"}

    def do_GET(self):
        if self.path in ("/", "/index.html"):
            self.send_response(302); self.send_header("Location", "web/"); self.end_headers(); return
        super().do_GET()

    def end_headers(self):
        self.send_header("Cross-Origin-Opener-Policy", "same-origin")
        self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
        self.send_header("Cross-Origin-Resource-Policy", "same-origin")
        self.send_header("Cache-Control", "no-cache")
        super().end_headers()

    def log_message(self, fmt, *a):
        if os.environ.get("TRADA_LOG"):
            sys.stderr.write("%s %s %s\n" % (self.headers.get("X-Real-IP") or self.client_address[0], self.headers.get("User-Agent", "")[:60], fmt % a))


socketserver.ThreadingTCPServer.allow_reuse_address = True
with socketserver.ThreadingTCPServer((HOST, PORT), H) as s:
    print(f"Trà Đá TTS demo: http://localhost:{PORT}/web/", flush=True)
    s.serve_forever()