From 34a9d018c6c90e3c28892d58e29589236c654de0 Mon Sep 17 00:00:00 2001 From: XXXXRT666 <157766680+XXXXRT666@users.noreply.github.com> Date: Thu, 4 Sep 2025 22:34:30 +0800 Subject: [PATCH] . --- .github/build_windows_packages.ps1 | 8 +-- GPT_SoVITS/TTS_infer_pack/TTS.py | 3 +- GPT_SoVITS/export_torch_script_v3v4.py | 9 +-- GPT_SoVITS/inference_webui.py | 2 +- api.py | 18 ++---- tools/AP_BWE/datasets1/dataset.py | 77 -------------------------- tools/audio_sr.py | 16 ++---- 7 files changed, 21 insertions(+), 112 deletions(-) diff --git a/.github/build_windows_packages.ps1 b/.github/build_windows_packages.ps1 index 67882ccc..d7177147 100644 --- a/.github/build_windows_packages.ps1 +++ b/.github/build_windows_packages.ps1 @@ -31,8 +31,8 @@ $UVR5_URL = "$baseHF/uvr5_weights.zip" $NLTK_URL = "$baseHF/nltk_data.zip" $JTALK_URL = "$baseHF/open_jtalk_dic_utf_8-1.11.tar.gz" -$PYTHON_VERSION = "3.11.12" -$PY_RELEASE_VERSION = "20250409" +$PYTHON_VERSION = "3.10.18" +$PY_RELEASE_VERSION = "20250902" Write-Host "[INFO] Cleaning .git..." Remove-Item "$srcDir\.git" -Recurse -Force -ErrorAction SilentlyContinue @@ -119,12 +119,12 @@ Write-Host "[INFO] Installing PyTorch..." switch ($cuda) { "cu126" { & ".\runtime\python.exe" -m pip install psutil ninja packaging wheel "setuptools>=42" --no-warn-script-location - & ".\runtime\python.exe" -m pip install torch torchaudio --index-url https://download.pytorch.org/whl/cu126 --no-warn-script-location + & ".\runtime\python.exe" -m pip install torch --index-url https://download.pytorch.org/whl/cu126 --no-warn-script-location & ".\runtime\python.exe" -m pip install flash-attn -i https://xxxxrt666.github.io/PIP-Index/ --no-build-isolation } "cu128" { & ".\runtime\python.exe" -m pip install psutil ninja packaging wheel "setuptools>=42" --no-warn-script-location - & ".\runtime\python.exe" -m pip install torch torchaudio --index-url https://download.pytorch.org/whl/cu128 --no-warn-script-location + & ".\runtime\python.exe" -m pip install torch --index-url https://download.pytorch.org/whl/cu128 --no-warn-script-location & ".\runtime\python.exe" -m pip install flash-attn -i https://xxxxrt666.github.io/PIP-Index/ --no-build-isolation } default { diff --git a/GPT_SoVITS/TTS_infer_pack/TTS.py b/GPT_SoVITS/TTS_infer_pack/TTS.py index bb9b1cef..621b99c9 100644 --- a/GPT_SoVITS/TTS_infer_pack/TTS.py +++ b/GPT_SoVITS/TTS_infer_pack/TTS.py @@ -721,7 +721,8 @@ class TTS: self.prompt_cache["refer_spec"][0] = spec_audio def _get_ref_spec(self, ref_audio_path): - raw_audio, raw_sr = torchaudio.load(ref_audio_path) + audio_n, raw_sr = librosa.load(ref_audio_path, sr=self.configs.sampling_rate) + raw_audio = torch.from_numpy(audio_n).unsqueeze(0) raw_audio = raw_audio.to(self.configs.device).float() self.prompt_cache["raw_audio"] = raw_audio self.prompt_cache["raw_sr"] = raw_sr diff --git a/GPT_SoVITS/export_torch_script_v3v4.py b/GPT_SoVITS/export_torch_script_v3v4.py index ee6ebef6..d4d03dc6 100644 --- a/GPT_SoVITS/export_torch_script_v3v4.py +++ b/GPT_SoVITS/export_torch_script_v3v4.py @@ -5,7 +5,6 @@ import librosa import numpy as np import soundfile import torch -import torchaudio import uvicorn from librosa.filters import mel as librosa_mel_fn @@ -16,7 +15,7 @@ from GPT_SoVITS.export_torch_script import ( spectrogram_torch, ) from GPT_SoVITS.f5_tts.model.backbones.dit import DiT -from GPT_SoVITS.inference_webui import get_phones_and_bert, get_spepc, norm_spec, resample, ssl_model +from GPT_SoVITS.inference_webui import get_phones_and_bert, get_spepc, norm_spec, ssl_model from GPT_SoVITS.module import commons from GPT_SoVITS.module.mel_processing import mel_spectrogram_torch from GPT_SoVITS.module.models_onnx import CFM, Generator, SynthesizerTrnV3 @@ -824,13 +823,11 @@ def export_1(ref_wav_path, ref_wav_text, version="v3"): gpt_sovits_half = ExportGPTSovitsV4Half(sovits.hps, script_t2s, trace_vq_model) torch.jit.script(gpt_sovits_half).save("onnx/ad/gpt_sovits_v4_half.pt") - ref_audio, sr = torchaudio.load(ref_wav_path) + tgt_sr = 24000 if version == "v3" else 32000 + ref_audio = torch.from_numpy(librosa.load(ref_wav_path, sr=tgt_sr)[0]).unsqueeze(0) ref_audio = ref_audio.to(device).float() if ref_audio.shape[0] == 2: ref_audio = ref_audio.mean(0).unsqueeze(0) - tgt_sr = 24000 if version == "v3" else 32000 - if sr != tgt_sr: - ref_audio = resample(ref_audio, sr, tgt_sr) # mel2 = mel_fn(ref_audio) mel2 = mel_fn(ref_audio) if version == "v3" else mel_fn_v4(ref_audio) mel2 = norm_spec(mel2) diff --git a/GPT_SoVITS/inference_webui.py b/GPT_SoVITS/inference_webui.py index 512a7968..2f4c771a 100644 --- a/GPT_SoVITS/inference_webui.py +++ b/GPT_SoVITS/inference_webui.py @@ -514,7 +514,7 @@ def resample(audio_tensor, sr0, sr1, device): def get_spepc(hps, filename, dtype, device, is_v2pro=False): sr1 = int(hps.data.sampling_rate) - audio_n, sr0 = librosa.load(filename, sr=sr1) + audio_n, _ = librosa.load(filename, sr=sr1) audio = torch.from_numpy(audio_n).to(device).unsqueeze(0) maxx = float(audio.abs().max()) diff --git a/api.py b/api.py index fbb46096..3f409331 100644 --- a/api.py +++ b/api.py @@ -616,18 +616,10 @@ class DictToAttrRecursive(dict): def get_spepc(hps, filename, dtype, device, is_v2pro=False): sr1 = int(hps.data.sampling_rate) - audio, sr0 = torchaudio.load(filename) - if sr0 != sr1: - audio = audio.to(device) - if audio.shape[0] == 2: - audio = audio.mean(0).unsqueeze(0) - audio = resample(audio, sr0, sr1, device) - else: - audio = audio.to(device) - if audio.shape[0] == 2: - audio = audio.mean(0).unsqueeze(0) + audio_n, _ = librosa.load(filename, sr=sr1) + audio = torch.from_numpy(audio_n).to(device).unsqueeze(0) - maxx = audio.abs().max() + maxx = float(audio.abs().max()) if maxx > 1: audio /= min(2, maxx) spec = spectrogram_torch( @@ -949,12 +941,12 @@ def get_tts_wav( phoneme_ids1 = torch.LongTensor(phones2).to(device).unsqueeze(0) fea_ref, ge = vq_model.decode_encp(prompt.unsqueeze(0), phoneme_ids0, refer) - ref_audio, sr = torchaudio.load(ref_wav_path) + tgt_sr = 24000 if version == "v3" else 32000 + ref_audio = torch.from_numpy(librosa.load(ref_wav_path, sr=tgt_sr)[0]).unsqueeze(0) ref_audio = ref_audio.to(device).float() if ref_audio.shape[0] == 2: ref_audio = ref_audio.mean(0).unsqueeze(0) - tgt_sr = 24000 if version == "v3" else 32000 if sr != tgt_sr: ref_audio = resample(ref_audio, sr, tgt_sr, device) mel2 = mel_fn(ref_audio) if version == "v3" else mel_fn_v4(ref_audio) diff --git a/tools/AP_BWE/datasets1/dataset.py b/tools/AP_BWE/datasets1/dataset.py index 40f993b5..6cf85e68 100644 --- a/tools/AP_BWE/datasets1/dataset.py +++ b/tools/AP_BWE/datasets1/dataset.py @@ -1,9 +1,4 @@ -import os -import random import torch -import torchaudio -import torch.utils.data -import torchaudio.functional as aF def amp_pha_stft(audio, n_fft, hop_size, win_size, center=True): @@ -34,75 +29,3 @@ def amp_pha_istft(log_amp, pha, n_fft, hop_size, win_size, center=True): audio = torch.istft(com, n_fft, hop_length=hop_size, win_length=win_size, window=hann_window, center=center) return audio - - -def get_dataset_filelist(a): - with open(a.input_training_file, "r", encoding="utf-8") as fi: - training_indexes = [x.split("|")[0] for x in fi.read().split("\n") if len(x) > 0] - - with open(a.input_validation_file, "r", encoding="utf-8") as fi: - validation_indexes = [x.split("|")[0] for x in fi.read().split("\n") if len(x) > 0] - - return training_indexes, validation_indexes - - -class Dataset(torch.utils.data.Dataset): - def __init__( - self, - training_indexes, - wavs_dir, - segment_size, - hr_sampling_rate, - lr_sampling_rate, - split=True, - shuffle=True, - n_cache_reuse=1, - device=None, - ): - self.audio_indexes = training_indexes - random.seed(1234) - if shuffle: - random.shuffle(self.audio_indexes) - self.wavs_dir = wavs_dir - self.segment_size = segment_size - self.hr_sampling_rate = hr_sampling_rate - self.lr_sampling_rate = lr_sampling_rate - self.split = split - self.cached_wav = None - self.n_cache_reuse = n_cache_reuse - self._cache_ref_count = 0 - self.device = device - - def __getitem__(self, index): - filename = self.audio_indexes[index] - if self._cache_ref_count == 0: - audio, orig_sampling_rate = torchaudio.load(os.path.join(self.wavs_dir, filename + ".wav")) - self.cached_wav = audio - self._cache_ref_count = self.n_cache_reuse - else: - audio = self.cached_wav - self._cache_ref_count -= 1 - - if orig_sampling_rate == self.hr_sampling_rate: - audio_hr = audio - else: - audio_hr = aF.resample(audio, orig_freq=orig_sampling_rate, new_freq=self.hr_sampling_rate) - - audio_lr = aF.resample(audio, orig_freq=orig_sampling_rate, new_freq=self.lr_sampling_rate) - audio_lr = aF.resample(audio_lr, orig_freq=self.lr_sampling_rate, new_freq=self.hr_sampling_rate) - audio_lr = audio_lr[:, : audio_hr.size(1)] - - if self.split: - if audio_hr.size(1) >= self.segment_size: - max_audio_start = audio_hr.size(1) - self.segment_size - audio_start = random.randint(0, max_audio_start) - audio_hr = audio_hr[:, audio_start : audio_start + self.segment_size] - audio_lr = audio_lr[:, audio_start : audio_start + self.segment_size] - else: - audio_hr = torch.nn.functional.pad(audio_hr, (0, self.segment_size - audio_hr.size(1)), "constant") - audio_lr = torch.nn.functional.pad(audio_lr, (0, self.segment_size - audio_lr.size(1)), "constant") - - return (audio_hr.squeeze(), audio_lr.squeeze()) - - def __len__(self): - return len(self.audio_indexes) diff --git a/tools/audio_sr.py b/tools/audio_sr.py index 9f936b1d..3f9f88ae 100644 --- a/tools/audio_sr.py +++ b/tools/audio_sr.py @@ -4,7 +4,7 @@ import json import os import torch -import torchaudio.functional as aF +import torchaudio from tools.AP_BWE.datasets1.dataset import amp_pha_istft, amp_pha_stft from tools.AP_BWE.models.model import APNet_BWE_Model @@ -38,12 +38,8 @@ class AP_BWE: return self def __call__(self, audio, orig_sampling_rate): - with torch.no_grad(): - # audio, orig_sampling_rate = torchaudio.load(inp_path) - # audio = audio.to(self.device) - audio = aF.resample(audio, orig_freq=orig_sampling_rate, new_freq=self.h.hr_sampling_rate) - amp_nb, pha_nb, com_nb = amp_pha_stft(audio, self.h.n_fft, self.h.hop_size, self.h.win_size) - amp_wb_g, pha_wb_g, com_wb_g = self.model(amp_nb, pha_nb) - audio_hr_g = amp_pha_istft(amp_wb_g, pha_wb_g, self.h.n_fft, self.h.hop_size, self.h.win_size) - # sf.write(opt_path, audio_hr_g.squeeze().cpu().numpy(), self.h.hr_sampling_rate, 'PCM_16') - return audio_hr_g.squeeze().cpu().numpy(), self.h.hr_sampling_rate + audio = torchaudio.functional.resample(audio, orig_freq=orig_sampling_rate, new_freq=self.h.hr_sampling_rate) + amp_nb, pha_nb, com_nb = amp_pha_stft(audio, self.h.n_fft, self.h.hop_size, self.h.win_size) + amp_wb_g, pha_wb_g, com_wb_g = self.model(amp_nb, pha_nb) + audio_hr_g = amp_pha_istft(amp_wb_g, pha_wb_g, self.h.n_fft, self.h.hop_size, self.h.win_size) + return audio_hr_g.squeeze().cpu().numpy(), self.h.hr_sampling_rate