Spaces:
Runtime error
Runtime error
zhzluke96 commited on
Commit ·
ec6a7d0
1
Parent(s): 02e90e4
update
Browse filesFiles changed (4)
12345678910111213141539 unmodified lines5556575859606162import numpy as npfrom pydub import AudioSegmentfrom typing import Any, List, Dict, Unionfrom scipy.io.wavfile import writeimport iofrom modules.utils.audio import time_stretch, pitch_shiftfrom modules import generate_audiofrom modules.normalization import text_normalizeimport loggingimport jsonimport randomimport copyfrom modules.speaker import Speaker39 unmodified linesclass SynthesizeSegments:batch_default_spk_seed = int(np.random.randint(0, 2**32 - 1))batch_default_infer_seed = int(np.random.randint(0, 2**32 - 1))def __init__(self, batch_size: int = 8):self.batch_size = batch_size12345678910111213141539 unmodified lines5556575859606162from pydub import AudioSegmentfrom typing import Any, List, Dict, Unionfrom scipy.io.wavfile import writeimport iofrom modules.utils import rngfrom modules.utils.audio import time_stretch, pitch_shiftfrom modules import generate_audiofrom modules.normalization import text_normalizeimport loggingimport jsonimport copyimport numpy as npfrom modules.speaker import Speaker39 unmodified linesclass SynthesizeSegments:batch_default_spk_seed = rng.np_rng()batch_default_infer_seed = rng.np_rng()def __init__(self, batch_size: int = 8):self.batch_size = batch_size
1234567891011121314import torchimport randomimport numpy as npdef deterministic(seed=0):random.seed(seed)np.random.seed(seed)torch.manual_seed(seed)if torch.cuda.is_available():torch.cuda.manual_seed_all(seed)torch.backends.cudnn.deterministic = Truetorch.backends.cudnn.benchmark = False12345678910111213141516import torchimport randomimport numpy as npfrom modules.utils import rngdef deterministic(seed=0):random.seed(seed)np.random.seed(seed)torch_rn = rng.convert_np_to_torch(seed)torch.manual_seed(torch_rn)if torch.cuda.is_available():torch.cuda.manual_seed_all(torch_rn)torch.backends.cudnn.deterministic = Truetorch.backends.cudnn.benchmark = False
1234567891011121314151617181920212223242526272829303132333435import numpy as npimport torchimport random
TORCH_RNG_MAX = -0x8000000000000000TORCH_RNG_MIN = 0xFFFFFFFFFFFFFFFF
NP_RNG_MAX = np.iinfo(np.uint32).maxNP_RNG_MIN = 0
def troch_rng(seed: int): torch.manual_seed(seed) random_float = torch.empty(1).uniform_().item() torch_rn = int(random_float * (TORCH_RNG_MAX - TORCH_RNG_MIN) + TORCH_RNG_MIN) np_rn = int(random_float * (NP_RNG_MAX - NP_RNG_MIN) + NP_RNG_MIN) return torch_rn, np_rn
def convert_np_to_torch(np_rn: int): random_float = (np_rn - NP_RNG_MIN) / (NP_RNG_MAX - NP_RNG_MIN) torch_rn = int(random_float * (TORCH_RNG_MAX - TORCH_RNG_MIN) + TORCH_RNG_MIN) return torch_rn
def np_rng(): return int(np.random.randint(NP_RNG_MIN, NP_RNG_MAX, dtype=np.uint32))
if __name__ == "__main__": import random
s1 = np_rng() s2 = troch_rng(s1) print(f"s1 {s1} => s2: {s2}")68 unmodified lines69707172737468 unmodified linesret_segments = []total_len = 0for seg in segments:total_len += len(seg["text"])if total_len > total_max:break68 unmodified lines697071727374757668 unmodified linesret_segments = []total_len = 0for seg in segments:if "text" not in seg:continuetotal_len += len(seg["text"])if total_len > total_max:break
modules/SynthesizeSegments.py+4-4
modules/utils/SeedContext.py+4-2
modules/utils/rng.pyAdded+35
webui.py+2