diff --git a/app/f5tts.py b/app/f5tts.py index 3ce9c8c..e0e5f0d 100644 --- a/app/f5tts.py +++ b/app/f5tts.py @@ -58,18 +58,18 @@ sway_sampling_coef = -1.0 speed = 1.0 def audio_ndarray_to_base64(waveform: np.ndarray, sample_rate: int = 16000) -> str: - # 如果是单通道,确保 shape 为 (samples, 1) - if waveform.ndim == 1: - waveform = waveform.reshape(-1, 1) + # 如果是单通道,确保 shape 为 (samples, 1) + if waveform.ndim == 1: + waveform = waveform.reshape(-1, 1) - # 写入内存 buffer(WAV 格式) - buffer = io.BytesIO() - sf.write(buffer, waveform, samplerate=sample_rate, format='WAV') - buffer.seek(0) + # 写入内存 buffer(WAV 格式) + buffer = io.BytesIO() + sf.write(buffer, waveform, samplerate=sample_rate, format='WAV') + buffer.seek(0) - # base64 编码 - b64_audio = base64.b64encode(buffer.read()).decode('utf-8') - return b64_audio + # base64 编码 + b64_audio = base64.b64encode(buffer.read()).decode('utf-8') + return b64_audio def write_wav_buffer(wav, nchannels, framerate): fs = FileStorage() @@ -219,7 +219,8 @@ class F5TTS: def setup_voices(self): config = getConfig() - workdir = get_serverenv('workdir') + workdir = config.workdir + print('workdir=', workdir) d = None with codecs.open(config.speakers_file, 'r', 'utf-8') as f: b = f.read() @@ -251,7 +252,7 @@ class F5TTS: async def add_voice(self, speaker, ref_audio, ref_text): config = getConfig() ref_audio = FileStorage().realPath(ref_audio) - workdir = get_serverenv('workdir') + workdir = config.workdir filename = f'{getID()}.wav' fn = f'{workdir}/samples/{filename}' await awaitify(self.copyfile)(ref_audio, fn) @@ -333,6 +334,7 @@ def init(): global f5 g = ServerEnv() f5 = F5TTS() + g.tts_engine = f5 g.infer_stream = f5.infer_stream g.inference_stream = f5.inference_stream g.get_speakers = f5.get_speakers diff --git a/conf/config.json b/conf/config.json index f74440e..375b476 100644 --- a/conf/config.json +++ b/conf/config.json @@ -21,6 +21,7 @@ "ref_audio":"ttt.wav", "ref_text":"快点吃饭,上课要迟到了。", "cross_fade_duration":0, + "workdir":"$[workdir]$", "filesroot":"$[workdir]$/files", "logger":{ "name":"f5tts", diff --git a/conf/speakers.json b/conf/speakers.json index 053725c..7aa3bee 100644 --- a/conf/speakers.json +++ b/conf/speakers.json @@ -1,6 +1,6 @@ { "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_audio": "samples/ymq.wav" + "ref_audio": "ymq.wav" } } diff --git a/f5tts.service b/f5tts.service index ba7ad69..eefb6e7 100644 --- a/f5tts.service +++ b/f5tts.service @@ -6,7 +6,8 @@ User=ymq Group=ymq WorkingDirectory=/share/ymq/run/f5tts Type=forking -ExecStart=/share/ymq/run/f5tts/run.sh +ExecStart=/share/ymq/run/f5tts/start.sh +ExecStop=/share/ymq/run/f5tts/stop.sh StandardOutput=append:/var/log/f5tts/f5tts.log StandardError=append:/var/log/f5tts/f5tts.log SyslogIdentifier=f5tts diff --git a/requirements.txt b/requirements.txt index 803220b..8030106 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,11 @@ numpy soundfile cached_path +redis pycld2 cn2an -apppublic -sqlor -ahserver -file2text +git+https://git.kaiyuancloud.cn/yumoqing/apppublic +git+https://git.kaiyuancloud.cn/yumoqing/sqlor +git+https://git.kaiyuancloud.cn/yumoqing/ahserver +git+https://git.kaiyuancloud.cn/yumoqing/filetxt # git+https://github.com/SWivid/F5-TTS diff --git a/run.sh b/run.sh deleted file mode 100755 index 74e5cad..0000000 --- a/run.sh +++ /dev/null @@ -1,5 +0,0 @@ -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 & - diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..64ea755 --- /dev/null +++ b/start.sh @@ -0,0 +1,10 @@ +#!/usr/bin/bash + +echo start 3 instances for f5tts engine +rundir=/share/ymq/run/f5tts +CUDA_VISIBLE_DEVICES=6 ${rundir}/f5tts.env/bin/python ${rundir}/app/f5tts.py -w ${rundir} -p 9995 & +CUDA_VISIBLE_DEVICES=6 ${rundir}/f5tts.env/bin/python ${rundir}/app/f5tts.py -w ${rundir} -p 9995 & +CUDA_VISIBLE_DEVICES=6 ${rundir}/f5tts.env/bin/python ${rundir}/app/f5tts.py -w ${rundir} -p 9995 & +CUDA_VISIBLE_DEVICES=6 ${rundir}/f5tts.env/bin/python ${rundir}/app/f5tts.py -w ${rundir} -p 9995 & + +exit 0 diff --git a/stop.sh b/stop.sh new file mode 100755 index 0000000..5478bee --- /dev/null +++ b/stop.sh @@ -0,0 +1,4 @@ +#!/usr/bin/bash + +killname f5tts.py +