This commit is contained in:
ymq1 2025-06-13 13:48:09 +00:00
parent 2b4d7594dc
commit c008d8f0f0
7 changed files with 33 additions and 23 deletions

View File

@ -219,11 +219,14 @@ class F5TTS:
def setup_voices(self): def setup_voices(self):
config = getConfig() config = getConfig()
workdir = get_serverenv('workdir')
d = None d = None
with codecs.open(config.speakers_file, 'r', 'utf-8') as f: with codecs.open(config.speakers_file, 'r', 'utf-8') as f:
b = f.read() b = f.read()
self.speakers = json.loads(b) self.speakers = json.loads(b)
ref_audio, ref_text = preprocess_ref_audio_text(config.ref_audio, config.ref_text) fn = f'{workdir}/samples/{config.ref_audio}'
ref_audio, ref_text = preprocess_ref_audio_text(fn,
config.ref_text)
self.voices = { self.voices = {
"main":{ "main":{
'ref_text':ref_text, 'ref_text':ref_text,
@ -231,7 +234,9 @@ class F5TTS:
} }
} }
for k,v in self.speakers.items(): for k,v in self.speakers.items():
ref_audio, ref_text = preprocess_ref_audio_text(v['ref_audio'], v['ref_text']) fn = f'{workdir}/samples/{v["ref_audio"]}'
ref_audio, ref_text = preprocess_ref_audio_text(fn,
v['ref_text'])
self.voices[k] = { self.voices[k] = {
'ref_text':ref_text, 'ref_text':ref_text,
'ref_audio':ref_audio 'ref_audio':ref_audio
@ -244,22 +249,22 @@ class F5TTS:
f1.write(b) f1.write(b)
async def add_voice(self, speaker, ref_audio, ref_text): async def add_voice(self, speaker, ref_audio, ref_text):
debug(f'{speaker=}, {ref_audio=}, {ref_text=}');
config = getConfig() config = getConfig()
ref_audio = FileStorage().realPath(ref_audio) ref_audio = FileStorage().realPath(ref_audio)
workdir = get_serverenv('workdir') workdir = get_serverenv('workdir')
fn = f'{workdir}/samples/{getID()}.wav' filename = f'{getID()}.wav'
fn = f'{workdir}/samples/{filename}'
await awaitify(self.copyfile)(ref_audio, fn) await awaitify(self.copyfile)(ref_audio, fn)
os.unlink(ref_adio) os.unlink(ref_adio)
self.speakers[speaker] = { self.speakers[speaker] = {
'ref_text':ref_text, 'ref_text':ref_text,
'ref_audio':fn 'ref_audio':filename
} }
f = awaitify(preprocess_ref_audio_text) f = awaitify(preprocess_ref_audio_text)
ref_audio, ref_text = await f(ref_audio, ref_text) ref_audio, ref_text = await f(ref_audio, ref_text)
self.voices[speaker] = { self.voices[speaker] = {
'ref_text':ref_text, 'ref_text':ref_text,
'ref_audio':fn 'ref_audio':filename
} }
with codecs.open(config.speakers_file, 'w', 'utf-8') as f: with codecs.open(config.speakers_file, 'w', 'utf-8') as f:
f.write(json.dumps(self.speakers, indent=4, ensure_ascii=False)) f.write(json.dumps(self.speakers, indent=4, ensure_ascii=False))

View File

@ -18,7 +18,7 @@
"remove_silence":false, "remove_silence":false,
"modelname":"F5-TTS", "modelname":"F5-TTS",
"device":"cuda:0", "device":"cuda:0",
"ref_audio":"$[workdir]$/samples/ttt.wav", "ref_audio":"ttt.wav",
"ref_text":"快点吃饭,上课要迟到了。", "ref_text":"快点吃饭,上课要迟到了。",
"cross_fade_duration":0, "cross_fade_duration":0,
"filesroot":"$[workdir]$/files", "filesroot":"$[workdir]$/files",

View File

@ -1,6 +1,6 @@
{ {
"ymq": { "ymq": {
"ref_text": "\u8f7b\u91cf\u5e94\u7528\u670d\u52a1\u5668\u5907\u6848\u6761\u4ef6\uff1a\u8d2d\u4e70\u65f6\u957f\u57283\u4e2a\u6708\u53ca\u4ee5\u4e0a", "ref_text": "\u8f7b\u91cf\u5e94\u7528\u670d\u52a1\u5668\u5907\u6848\u6761\u4ef6\uff1a\u8d2d\u4e70\u65f6\u957f\u57283\u4e2a\u6708\u53ca\u4ee5\u4e0a",
"ref_audio": "/data/ymq/py/f5tts/files/87/103/66/49/record.wav" "ref_audio": "samples/ymq.wav"
} }
} }

15
f5tts.service Normal file
View File

@ -0,0 +1,15 @@
[Unit]
Wants=systemd-networkd.service
[Service]
User=ymq
Group=ymq
WorkingDirectory=/share/ymq/run/f5tts
Type=forking
ExecStart=/share/ymq/run/f5tts/run.sh
StandardOutput=append:/var/log/f5tts/f5tts.log
StandardError=append:/var/log/f5tts/f5tts.log
SyslogIdentifier=f5tts
[Install]
WantedBy=multi-user.target

View File

@ -1,15 +0,0 @@
Building prefix dict from the default dictionary ...
Loading model from cache /tmp/jieba.cache
Loading model cost 0.794 seconds.
Prefix dict has been built successfully.
/d/f5tts/py3/lib/python3.12/site-packages/asyncssh/crypto/cipher.py:29: CryptographyDeprecationWarning: ARC4 has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.ARC4 and will be removed from cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0.
from cryptography.hazmat.primitives.ciphers.algorithms import AES, ARC4
/d/f5tts/py3/lib/python3.12/site-packages/asyncssh/crypto/cipher.py:30: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0.
from cryptography.hazmat.primitives.ciphers.algorithms import TripleDES
/d/f5tts/py3/lib/python3.12/site-packages/transformers/models/whisper/generation_whisper.py:509: FutureWarning: The input name `inputs` is deprecated. Please make sure to use `input_features` instead.
warnings.warn(
You have passed task=transcribe, but also have set `forced_decoder_ids` to [[1, None], [2, 50360]] which creates a conflict. `forced_decoder_ids` will be ignored in favor of task=transcribe.
Passing a tuple of `past_key_values` is deprecated and will be removed in Transformers v4.43.0. You should pass an instance of `EncoderDecoderCache` instead, e.g. `past_key_values=EncoderDecoderCache.from_legacy_cache(past_key_values)`.
The attention mask is not set and cannot be inferred from input because pad token is same as eos token. As a consequence, you may observe unexpected behavior. Please pass your input's `attention_mask` to obtain reliable results.
/d/f5tts/py3/lib/python3.12/site-packages/transformers/models/whisper/generation_whisper.py:509: FutureWarning: The input name `inputs` is deprecated. Please make sure to use `input_features` instead.
warnings.warn(

5
run.sh Executable file
View File

@ -0,0 +1,5 @@
echo start 3 instances for f5tts engine
rundir=/share/ymq/run/f5tts
CUDA_VISIBLE_DEVICES=4 ${rundir}/f5tts.env/bin/python ${rundir}/app/f5tts.py -w ${rundir} -p 9995 &
CUDA_VISIBLE_DEVICES=4 ${rundir}/f5tts.env/bin/python ${rundir}/app/f5tts.py -w ${rundir} -p 9995 &