bugfix
This commit is contained in:
parent
2f6c70f836
commit
33c535bec4
18
app/f5tts.py
18
app/f5tts.py
@ -1,4 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
import io
|
||||||
|
import base64
|
||||||
import sys
|
import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
import codecs
|
import codecs
|
||||||
@ -125,8 +127,7 @@ class F5TTS:
|
|||||||
return {
|
return {
|
||||||
'text': gen_text,
|
'text': gen_text,
|
||||||
'audio':audio,
|
'audio':audio,
|
||||||
'sample_rate':final_sample_rate,
|
'sample_rate':final_sample_rate
|
||||||
'spectragram':spectragram
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def speed_convert(self, output_audio_np, speed_factor):
|
def speed_convert(self, output_audio_np, speed_factor):
|
||||||
@ -151,6 +152,7 @@ class F5TTS:
|
|||||||
|
|
||||||
async def split_text(self, text_gen, speaker):
|
async def split_text(self, text_gen, speaker):
|
||||||
chunks = split_text_with_dialog_preserved(text_gen)
|
chunks = split_text_with_dialog_preserved(text_gen)
|
||||||
|
debug(f'{len(chunks)=}')
|
||||||
# reg2 = self.config.speaker_match
|
# reg2 = self.config.speaker_match
|
||||||
reg2 = r"\[\[(\w+)\]\]"
|
reg2 = r"\[\[(\w+)\]\]"
|
||||||
ret = []
|
ret = []
|
||||||
@ -183,6 +185,7 @@ class F5TTS:
|
|||||||
async def _inference_stream(self, prompt, speaker, speed_factor=1.0):
|
async def _inference_stream(self, prompt, speaker, speed_factor=1.0):
|
||||||
text_gen = prompt
|
text_gen = prompt
|
||||||
chunks = await self.split_text(prompt, speaker)
|
chunks = await self.split_text(prompt, speaker)
|
||||||
|
debug(f'{len(chunks)=}')
|
||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
gen_text = chunk['text']
|
gen_text = chunk['text']
|
||||||
ref_audio = chunk['ref_audio']
|
ref_audio = chunk['ref_audio']
|
||||||
@ -196,10 +199,17 @@ class F5TTS:
|
|||||||
debug(f'{gen_text=} inference error\n{format_exc()}')
|
debug(f'{gen_text=} inference error\n{format_exc()}')
|
||||||
|
|
||||||
async def inference_stream(self, prompt, speaker, speed_factor=1.0):
|
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'])
|
audio_b64=audio_ndarray_to_base64(d['audio'], d['sample_rate'])
|
||||||
d['audio'] = audio_b64
|
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):
|
def setup_voices(self):
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
|
@ -1,46 +1,42 @@
|
|||||||
{
|
{
|
||||||
"widgettype":"VBox",
|
"widgettype":"HBox",
|
||||||
"options":{
|
"options":{
|
||||||
"height":"100%"
|
"height":"100%"
|
||||||
},
|
},
|
||||||
"subwidgets":[
|
"subwidgets":[
|
||||||
{
|
{
|
||||||
"widgettype":"Filler",
|
"widgettype":"Form",
|
||||||
"options":{},
|
"id":"form",
|
||||||
"subwidgets":[
|
"options":{
|
||||||
{
|
"width":"50%",
|
||||||
"widgettype":"Form",
|
"title":"流式返回",
|
||||||
"id":"form",
|
"submit_url":"{{entire_url('/v1/infer_stream')}}",
|
||||||
"options":{
|
"fields":[
|
||||||
"title":"流式返回",
|
{
|
||||||
"submit_url":"{{entire_url('/v1/infer_stream')}}",
|
"name":"speaker",
|
||||||
"fields":[
|
"label":"播音员",
|
||||||
{
|
"uitype":"code",
|
||||||
"name":"speaker",
|
"value":"main",
|
||||||
"label":"播音员",
|
"dataurl":"{{entire_url('/get_speakers.dspy')}}"
|
||||||
"uitype":"code",
|
},
|
||||||
"value":"main",
|
{
|
||||||
"dataurl":"{{entire_url('/get_speakers.dspy')}}"
|
"name":"prompt",
|
||||||
},
|
"label":"文本",
|
||||||
{
|
"uitype":"text",
|
||||||
"name":"prompt",
|
"uiparams":{
|
||||||
"label":"文本",
|
"rows":20,
|
||||||
"uitype":"text",
|
"cols":80
|
||||||
"uiparams":{
|
}
|
||||||
"rows":20,
|
|
||||||
"cols":80
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id":"audio",
|
"id":"audio",
|
||||||
"widgettype":"AudioPlayer",
|
"widgettype":"TextedAudioPlayer",
|
||||||
"options":{
|
"options":{
|
||||||
"height":"40px",
|
"width": "50%",
|
||||||
|
"height":"100%",
|
||||||
"auto_play":true
|
"auto_play":true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# normal mode
|
# normal mode
|
||||||
|
debug(f'{params_kw=}')
|
||||||
speaker = params_kw.speaker or 'main'
|
speaker = params_kw.speaker or 'main'
|
||||||
path = await infer(params_kw.prompt, speaker)
|
path = await infer(params_kw.prompt, speaker)
|
||||||
ret = entire_url(f'/idfile?path={path}')
|
ret = entire_url(f'/idfile?path={path}')
|
||||||
|
Loading…
Reference in New Issue
Block a user