-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgi.py
44 lines (34 loc) · 1009 Bytes
/
wsgi.py
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
36
37
38
39
40
41
42
43
44
#! /usr/bin/env python3
# vim:fenc=utf-8
#
# Copyright © 2023 sandvich <sandvich@artix>
#
# Distributed under terms of the GPLv3 license.
from flask import Flask, request, send_file
import tokens
from tokens import Group
from tokenizer import Tokenizer
from bitcoin_miner import BitcoinMiner
app = Flask(__name__)
bitcoin_miner = BitcoinMiner(False, 4)
bitcoin_miner.update_model("udisen")
tokens.speech_synthesizer = bitcoin_miner
@app.route("/")
def root_path():
return "Your mom"
@app.route("/", methods=["POST"]) # type: ignore
def request_synthesis():
content = request.get_data(as_text=True)
if content is None:
return "Bad request", 400
outfile = synthesize(content)
if outfile is None:
return 500
return send_file(outfile, mimetype="audio/wav")
def synthesize(text: str) -> str | None:
root = Group([])
Tokenizer(text, root).tokenize(root)
root.outfile = "audio.wav"
if root.synthesize():
return root.outfile
return None