diff --git a/app/f5tts.py b/app/f5tts.py index 42a5151..6da29cb 100644 --- a/app/f5tts.py +++ b/app/f5tts.py @@ -1,4 +1,6 @@ import os +import io +import base64 import sys import asyncio import codecs @@ -125,8 +127,7 @@ class F5TTS: return { 'text': gen_text, 'audio':audio, - 'sample_rate':final_sample_rate, - 'spectragram':spectragram + 'sample_rate':final_sample_rate } def speed_convert(self, output_audio_np, speed_factor): @@ -151,6 +152,7 @@ class F5TTS: async def split_text(self, text_gen, speaker): chunks = split_text_with_dialog_preserved(text_gen) + debug(f'{len(chunks)=}') # reg2 = self.config.speaker_match reg2 = r"\[\[(\w+)\]\]" ret = [] @@ -183,6 +185,7 @@ class F5TTS: async def _inference_stream(self, prompt, speaker, speed_factor=1.0): text_gen = prompt chunks = await self.split_text(prompt, speaker) + debug(f'{len(chunks)=}') for chunk in chunks: gen_text = chunk['text'] ref_audio = chunk['ref_audio'] @@ -196,10 +199,17 @@ class F5TTS: debug(f'{gen_text=} inference error\n{format_exc()}') async def inference_stream(self, prompt, speaker, speed_factor=1.0): - for d in self._inference_stream(prompt, speaker, speed_factor=speed_factor): + async for d in self._inference_stream(prompt, speaker, speed_factor=speed_factor): audio_b64=audio_ndarray_to_base64(d['audio'], d['sample_rate']) d['audio'] = audio_b64 - yield d + d['done'] = False + txt = json.dumps(d, ensure_ascii=False) + yield txt + '\n' + d = { + 'done': True + } + txt = json.dumps(d, ensure_ascii=False) + yield txt + '\n' def setup_voices(self): config = getConfig() diff --git a/wwwroot/tts_stream.ui b/wwwroot/tts_stream.ui index 5048b77..337fc5a 100644 --- a/wwwroot/tts_stream.ui +++ b/wwwroot/tts_stream.ui @@ -1,46 +1,42 @@ { - "widgettype":"VBox", + "widgettype":"HBox", "options":{ "height":"100%" }, "subwidgets":[ { - "widgettype":"Filler", - "options":{}, - "subwidgets":[ - { - "widgettype":"Form", - "id":"form", - "options":{ - "title":"流式返回", - "submit_url":"{{entire_url('/v1/infer_stream')}}", - "fields":[ - { - "name":"speaker", - "label":"播音员", - "uitype":"code", - "value":"main", - "dataurl":"{{entire_url('/get_speakers.dspy')}}" - }, - { - "name":"prompt", - "label":"文本", - "uitype":"text", - "uiparams":{ - "rows":20, - "cols":80 - } - } - ] + "widgettype":"Form", + "id":"form", + "options":{ + "width":"50%", + "title":"流式返回", + "submit_url":"{{entire_url('/v1/infer_stream')}}", + "fields":[ + { + "name":"speaker", + "label":"播音员", + "uitype":"code", + "value":"main", + "dataurl":"{{entire_url('/get_speakers.dspy')}}" + }, + { + "name":"prompt", + "label":"文本", + "uitype":"text", + "uiparams":{ + "rows":20, + "cols":80 + } } - } - ] + ] + } }, { "id":"audio", - "widgettype":"AudioPlayer", + "widgettype":"TextedAudioPlayer", "options":{ - "height":"40px", + "width": "50%", + "height":"100%", "auto_play":true } } diff --git a/wwwroot/v1/inference/index.dspy b/wwwroot/v1/inference/index.dspy index 22d53f6..190a9f8 100644 --- a/wwwroot/v1/inference/index.dspy +++ b/wwwroot/v1/inference/index.dspy @@ -1,4 +1,5 @@ # normal mode +debug(f'{params_kw=}') speaker = params_kw.speaker or 'main' path = await infer(params_kw.prompt, speaker) ret = entire_url(f'/idfile?path={path}')