From 288900d128f5606b6c30a490315849b2e3bac406 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 6 Aug 2024 14:23:14 +0800 Subject: [PATCH] bugfix --- app/t.py | 14 +++++++++ app/tts.py | 57 +++++++++++++++++++++++++++++++++++++ conf/config.json | 71 ++++++++++++++++++++++++++++++++++++++++++++++ logs/README.md | 0 tts | 4 +++ wwwroot/index.html | 0 6 files changed, 146 insertions(+) create mode 100644 app/t.py create mode 100644 app/tts.py create mode 100755 conf/config.json create mode 100644 logs/README.md create mode 100644 tts create mode 100644 wwwroot/index.html diff --git a/app/t.py b/app/t.py new file mode 100644 index 0000000..24d6187 --- /dev/null +++ b/app/t.py @@ -0,0 +1,14 @@ +import ChatTTS +import torch +import torchaudio + +chat = ChatTTS.Chat() +chat.load(compile=False) # Set to True for better performance + +texts = ["PUT YOUR 1st TEXT HERE", "PUT YOUR 2nd TEXT HERE"] + +wavs = chat.infer(texts) + +for i in range(len(wavs)): + torchaudio.save(f"basic_output{i}.wav", torch.from_numpy(wavs[i]).unsqueeze(0), 24000) + diff --git a/app/tts.py b/app/tts.py new file mode 100644 index 0000000..aa2c6d5 --- /dev/null +++ b/app/tts.py @@ -0,0 +1,57 @@ +import os, sys +import argparse +from appPublic.log import MyLogger, info, debug, warning +from appPublic.folderUtils import ProgramPath +from appPublic.jsonConfig import getConfig +from appPublic.registerfunction import RegisterFunction +from appPublic.worker import awaitify +from ahserver.configuredServer import ConfiguredServer +from ahserver.serverenv import ServerEnv +from io import BytesIO + +import ChatTTS +__version__ = '0.0.1' + +class TTS: + def __init__(self): + self.engine = ChatTTS.Chat() + self.engine.load(compile=True) + + def _generate(request, **kw): + params_kw = kw.get('params_kw') + text = params_kw.get('prompt') + wavs = self.engine.refer(text) + f = BytesIO() + torchaudio.save(f, touch.from_numpy(wavs[0]).unsqueeze(0), 24000) + f.seek(0,0) + return f.read() + + generate = awaitify(_generate) + +if __name__ == '__main__': + parser = argparse.ArgumentParser(prog="tts") + parser.add_argument('-w', '--workdir') + parser.add_argument('-p', '--port') + args = parser.parse_args() + print(args) + workdir = args.workdir or os.getcwd() + p = ProgramPath() + config = getConfig(workdir, NS={'workdir':workdir, 'ProgramPath':p}) + if config.logger: + logger = MyLogger(config.logger.name or 'tts', + levelname=config.logger.levelname or 'debug', + logfile=config.logger.logfile or None) + else: + logger = MyLogger('sage', levelname='debug') + + info(f'========tts version={__version__}========') + # server = ConfiguredServer(auth_klass=MyAuthAPI, workdir=workdir) + server = ConfiguredServer(workdir=workdir) + tts = TTS() + rf = RegisterFunction() + rf.register('generate', tts.generate) + info(f'{rf.registKW=}') + port = args.port or config.website.port or 8080 + port = int(port) + server.run(port=port) + diff --git a/conf/config.json b/conf/config.json new file mode 100755 index 0000000..ab34fa9 --- /dev/null +++ b/conf/config.json @@ -0,0 +1,71 @@ +{ + "logger":{ + "name":"tts", + "levelname":"info", + "logfile":"$[workdir]$/logs/tts.log" + }, + "definitions":{ + "whisper_model":"/d/ymq/osc/models/whisper/large-v3.pt" + }, + "filesroot":"$[workdir]$/files", + "website":{ + "paths":[ + ["$[workdir]$/wwwroot",""] + ], + "client_max_size":10000, + "host":"0.0.0.0", + "port":9092, + "coding":"utf-8", + "ssl_gg":{ + "crtfile":"$[workdir]$/conf/www.bsppo.com.pem", + "keyfile":"$[workdir]$/conf/www.bsppo.com.key" + }, + "indexes":[ + "index.html", + "index.tmpl", + "index.ui", + "index.dspy", + "index.md" + ], + "startswiths":[ + { + "leading":"/generate", + "registerfunction":"generate" + } + ], + "processors":[ + [".ws","ws"], + [".xterm","xterm"], + [".proxy","proxy"], + [".llm", "llm"], + [".llms", "llms"], + [".llma", "llma"], + [".xlsxds","xlsxds"], + [".sqlds","sqlds"], + [".tmpl.js","tmpl"], + [".tmpl.css","tmpl"], + [".html.tmpl","tmpl"], + [".bcrud", "bricks_crud"], + [".tmpl","tmpl"], + [".bui","bui"], + [".ui","bui"], + [".dspy","dspy"], + [".md","md"] + ], + "rsakey":{ + "privatekey":"$[workdir]$/conf/rsa_private_key.pem", + "publickey":"$[workdir]$/conf/rsa_public_key.pem" + }, + "session_max_time":3000, + "session_issue_time":2500, + "session_redis_oops":{ + "url":"redis://127.0.0.1:6379" + } + }, + "langMapping":{ + "zh-Hans-CN":"zh-cn", + "zh-CN":"zh-cn", + "en-us":"en", + "en-US":"en" + } +} diff --git a/logs/README.md b/logs/README.md new file mode 100644 index 0000000..e69de29 diff --git a/tts b/tts new file mode 100644 index 0000000..5fdbbcc --- /dev/null +++ b/tts @@ -0,0 +1,4 @@ +#!/usr/bin/bash + +source py3/bin/activate +python app/tts.py >> tts.out diff --git a/wwwroot/index.html b/wwwroot/index.html new file mode 100644 index 0000000..e69de29