From 329d7d0545e36147a9e9816db1448abb0bb2b2c1 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 7 Aug 2024 13:06:53 +0800 Subject: [PATCH] bugfix --- app/tts.py | 30 +++++++++++++++++++----------- conf/config.json | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/tts.py b/app/tts.py index 9e97c66..0840911 100644 --- a/app/tts.py +++ b/app/tts.py @@ -1,11 +1,14 @@ import os, sys +import torch +import torchaudio import argparse from appPublic.log import MyLogger, info, debug, warning -from appPublic.folderUtils import ProgramPath +from appPublic.folderUtils import ProgramPath, temp_file from appPublic.jsonConfig import getConfig from appPublic.registerfunction import RegisterFunction -from appPublic.worker import awaitify +from appPublic.worker import coroutinify from ahserver.configuredServer import ConfiguredServer +from ahserver.globalEnv import get_definition from ahserver.serverenv import ServerEnv from io import BytesIO @@ -15,20 +18,25 @@ __version__ = '0.0.1' class TTS: def __init__(self): self.engine = ChatTTS.Chat() + custom_path=get_definition('chattts_model_path') + print(custom_path) self.engine.load(source='custom', - custom_path=get_definition(custom_path='chattts_model_path', + custom_path=get_definition('chattts_model_path'), compile=True) - def _generate(request, **kw): + def _generate(self, 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) + wavs = self.engine.infer(text) + fn = temp_file(suffix='.wav') + torchaudio.save(fn, torch.from_numpy(wavs[0]).unsqueeze(0), 24000, format='wav') + with open(fn, 'rb') as f: + b = f.read() + os.remove(fn) + return b + os.remove(fn) + + generate = coroutinify(_generate) if __name__ == '__main__': parser = argparse.ArgumentParser(prog="tts") diff --git a/conf/config.json b/conf/config.json index 67074d3..2d4229f 100755 --- a/conf/config.json +++ b/conf/config.json @@ -5,7 +5,7 @@ "logfile":"$[workdir]$/logs/tts.log" }, "definitions":{ - "chattts_model_path":"/d/ymq/osc/models/ChaTTTS" + "chattts_model_path":"/Users/ymq/models/ChaTTTS" }, "filesroot":"$[workdir]$/files", "website":{