This commit is contained in:
yumoqing 2024-08-06 14:23:14 +08:00
parent 9b29337ec4
commit 288900d128
6 changed files with 146 additions and 0 deletions

14
app/t.py Normal file
View File

@ -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)

57
app/tts.py Normal file
View File

@ -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)

71
conf/config.json Executable file
View File

@ -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"
}
}

0
logs/README.md Normal file
View File

4
tts Normal file
View File

@ -0,0 +1,4 @@
#!/usr/bin/bash
source py3/bin/activate
python app/tts.py >> tts.out

0
wwwroot/index.html Normal file
View File