mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2026-07-08 15:51:09 +08:00
.
This commit is contained in:
parent
dead5ebd2c
commit
34a9d018c6
8
.github/build_windows_packages.ps1
vendored
8
.github/build_windows_packages.ps1
vendored
@ -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 {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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())
|
||||
|
||||
18
api.py
18
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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user