Spaces:
Running
Running
zhzluke96
commited on
Commit
•
ec6a7d0
1
Parent(s):
02e90e4
update
Browse files- modules/SynthesizeSegments.py +4 -4
- modules/utils/SeedContext.py +4 -2
- modules/utils/rng.py +35 -0
- webui.py +2 -0
modules/SynthesizeSegments.py
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
-
import numpy as np
|
2 |
from pydub import AudioSegment
|
3 |
from typing import Any, List, Dict, Union
|
4 |
from scipy.io.wavfile import write
|
5 |
import io
|
|
|
6 |
from modules.utils.audio import time_stretch, pitch_shift
|
7 |
from modules import generate_audio
|
8 |
from modules.normalization import text_normalize
|
9 |
import logging
|
10 |
import json
|
11 |
-
import random
|
12 |
import copy
|
|
|
13 |
|
14 |
from modules.speaker import Speaker
|
15 |
|
@@ -55,8 +55,8 @@ def to_number(value, t, default=0):
|
|
55 |
|
56 |
|
57 |
class SynthesizeSegments:
|
58 |
-
batch_default_spk_seed =
|
59 |
-
batch_default_infer_seed =
|
60 |
|
61 |
def __init__(self, batch_size: int = 8):
|
62 |
self.batch_size = batch_size
|
|
|
|
|
1 |
from pydub import AudioSegment
|
2 |
from typing import Any, List, Dict, Union
|
3 |
from scipy.io.wavfile import write
|
4 |
import io
|
5 |
+
from modules.utils import rng
|
6 |
from modules.utils.audio import time_stretch, pitch_shift
|
7 |
from modules import generate_audio
|
8 |
from modules.normalization import text_normalize
|
9 |
import logging
|
10 |
import json
|
|
|
11 |
import copy
|
12 |
+
import numpy as np
|
13 |
|
14 |
from modules.speaker import Speaker
|
15 |
|
|
|
55 |
|
56 |
|
57 |
class SynthesizeSegments:
|
58 |
+
batch_default_spk_seed = rng.np_rng()
|
59 |
+
batch_default_infer_seed = rng.np_rng()
|
60 |
|
61 |
def __init__(self, batch_size: int = 8):
|
62 |
self.batch_size = batch_size
|
modules/utils/SeedContext.py
CHANGED
@@ -1,14 +1,16 @@
|
|
1 |
import torch
|
2 |
import random
|
3 |
import numpy as np
|
|
|
4 |
|
5 |
|
6 |
def deterministic(seed=0):
|
7 |
random.seed(seed)
|
8 |
np.random.seed(seed)
|
9 |
-
|
|
|
10 |
if torch.cuda.is_available():
|
11 |
-
torch.cuda.manual_seed_all(
|
12 |
torch.backends.cudnn.deterministic = True
|
13 |
torch.backends.cudnn.benchmark = False
|
14 |
|
|
|
1 |
import torch
|
2 |
import random
|
3 |
import numpy as np
|
4 |
+
from modules.utils import rng
|
5 |
|
6 |
|
7 |
def deterministic(seed=0):
|
8 |
random.seed(seed)
|
9 |
np.random.seed(seed)
|
10 |
+
torch_rn = rng.convert_np_to_torch(seed)
|
11 |
+
torch.manual_seed(torch_rn)
|
12 |
if torch.cuda.is_available():
|
13 |
+
torch.cuda.manual_seed_all(torch_rn)
|
14 |
torch.backends.cudnn.deterministic = True
|
15 |
torch.backends.cudnn.benchmark = False
|
16 |
|
modules/utils/rng.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import torch
|
3 |
+
import random
|
4 |
+
|
5 |
+
TORCH_RNG_MAX = -0x8000000000000000
|
6 |
+
TORCH_RNG_MIN = 0xFFFFFFFFFFFFFFFF
|
7 |
+
|
8 |
+
NP_RNG_MAX = np.iinfo(np.uint32).max
|
9 |
+
NP_RNG_MIN = 0
|
10 |
+
|
11 |
+
|
12 |
+
def troch_rng(seed: int):
|
13 |
+
torch.manual_seed(seed)
|
14 |
+
random_float = torch.empty(1).uniform_().item()
|
15 |
+
torch_rn = int(random_float * (TORCH_RNG_MAX - TORCH_RNG_MIN) + TORCH_RNG_MIN)
|
16 |
+
np_rn = int(random_float * (NP_RNG_MAX - NP_RNG_MIN) + NP_RNG_MIN)
|
17 |
+
return torch_rn, np_rn
|
18 |
+
|
19 |
+
|
20 |
+
def convert_np_to_torch(np_rn: int):
|
21 |
+
random_float = (np_rn - NP_RNG_MIN) / (NP_RNG_MAX - NP_RNG_MIN)
|
22 |
+
torch_rn = int(random_float * (TORCH_RNG_MAX - TORCH_RNG_MIN) + TORCH_RNG_MIN)
|
23 |
+
return torch_rn
|
24 |
+
|
25 |
+
|
26 |
+
def np_rng():
|
27 |
+
return int(np.random.randint(NP_RNG_MIN, NP_RNG_MAX, dtype=np.uint32))
|
28 |
+
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
import random
|
32 |
+
|
33 |
+
s1 = np_rng()
|
34 |
+
s2 = troch_rng(s1)
|
35 |
+
print(f"s1 {s1} => s2: {s2}")
|
webui.py
CHANGED
@@ -69,6 +69,8 @@ def segments_length_limit(segments, total_max: int):
|
|
69 |
ret_segments = []
|
70 |
total_len = 0
|
71 |
for seg in segments:
|
|
|
|
|
72 |
total_len += len(seg["text"])
|
73 |
if total_len > total_max:
|
74 |
break
|
|
|
69 |
ret_segments = []
|
70 |
total_len = 0
|
71 |
for seg in segments:
|
72 |
+
if "text" not in seg:
|
73 |
+
continue
|
74 |
total_len += len(seg["text"])
|
75 |
if total_len > total_max:
|
76 |
break
|