* rename webui.py to run_webui.py * remove unused imports * remove unsued code * move inference code and fix all warnings * move web app code * make code easier to read * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove unused function * remove msgpack_api.py * rename API files * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * finish updating the doc with the new file names * finish updating the doc with the new file names * fix CPU use in the API * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor WebUIinference in a class with submodules * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * re-enable streaming in webui inference code * generalize inference code in webui * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * minor fix * make a unique inference engine class * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * minor fix * cleaning code * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * implement new structure of the API (not working) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor API * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * minor fixes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * reimplement chat endpoint * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
from http import HTTPStatus
|
|
|
|
import numpy as np
|
|
from kui.asgi import HTTPException
|
|
|
|
from tools.inference_engine import TTSInferenceEngine
|
|
from tools.schema import ServeTTSRequest
|
|
|
|
AMPLITUDE = 32768 # Needs an explaination
|
|
|
|
|
|
def inference_wrapper(req: ServeTTSRequest, engine: TTSInferenceEngine):
|
|
"""
|
|
Wrapper for the inference function.
|
|
Used in the API server.
|
|
"""
|
|
for result in engine.inference(req):
|
|
match result.code:
|
|
case "header":
|
|
if isinstance(result.audio, tuple):
|
|
yield result.audio[1]
|
|
|
|
case "error":
|
|
raise HTTPException(
|
|
HTTPStatus.INTERNAL_SERVER_ERROR,
|
|
content=str(result.error),
|
|
)
|
|
|
|
case "segment":
|
|
if isinstance(result.audio, tuple):
|
|
yield (result.audio[1] * AMPLITUDE).astype(np.int16).tobytes()
|
|
|
|
case "final":
|
|
if isinstance(result.audio, tuple):
|
|
yield result.audio[1]
|
|
return None # Stop the generator
|
|
|
|
raise HTTPException(
|
|
HTTPStatus.INTERNAL_SERVER_ERROR,
|
|
content="No audio generated, please check the input text.",
|
|
)
|