<jupyter_start><jupyter_text>This notebook should allow adding more channels to the WN layers without resetting the old weights.1 - Currently NOT working<jupyter_code>import torch
import os

# move to waveflow directory
os.chdir(r"G:\TwiBot\tacotron2\waveglow_latest")<jupyter_output><empty_output><jupyter_text>merging arrays<jupyter_code>arr = [[['audio_0.wav',22050], ['audio_1.wav',44100], ['audio_2.wav',48000],],[['audio_0.wav',22050], ['audio_1.wav',44100], ['audio_2.wav',48000],]]
out = []
_ = [out.extend(x) for x in arr]
print(out)
print( f';{"dataset":<23}|{"dataset_type":<20}|{"speaker_name":<32}|{"speaker_id":<10}|duration_hrs' )
print( f'{"My Little Pony":<24}|{"Show":<20}|{"Twilight":<32}|{279:<10}|{2.5984:>8.4f}' )
print( f'{"My Little Pony":<24}|{"Show":<20}|{"Mean Twilight Sparkle":<32}|{279:<10}|{2.5984:>8.4f}' )
print( f'{"My Little Pony":<24}|{"Show":<20}|{"Celestia":<32}|{279:<10}|{2.5984:>8.4f}' )
print( f'{"A Little Bit Wicked":<24}|{"Audiobook":<20}|{"<NAME>":<32}|{280:<10}|{1.1245665464:>8.4f}' )
print( f'{"VCTK":<24}|{"Newspaper Extracts":<20}|{"p239":<32}|{281:<10}|{0.7531:>8.4f}' )
print( f'{"VCTK":<24}|{"Newspaper Extracts":<20}|{"p240":<32}|{282:<10}|{0.6554:>8.4f}' )
print( f'{"VCTK":<24}|{"Newspaper Extracts":<20}|{"p241":<32}|{283:<10}|{0.6815:>8.4f}' )
print( f'{"LJSpeech":<24}|{"Audiobook":<20}|{"LJSpeech":<32}|{284:<10}|{23.4785:>8.4f}' )<jupyter_output>;dataset                |dataset_type        |speaker_name                    |speaker_id|duration_hrs
My Little Pony          |Show                |Twilight                        |279       |  2.5984
My Little Pony          |Show                |Mean Twilight Sparkle           |279       |  2.5984
My Little Pony          |Show                |Celestia                        |279       |  2.5984
A Little Bit Wicked     |Audiobook           |<NAME>              |280       |  1.1246
VCTK                    |Newspaper Extracts  |p239                            |281       |  0.7531
VCTK                    |Newspaper Extracts  |p240                            |282       |  0.6554
VCTK                    |Newspaper Extracts  |p241                            |283       |  0.6815
LJSpeech                |Audiobook           |LJSpeech                        |284       | 23.4785<jupyter_text>merging dicts<jupyter_code>aarr = [[['audio_0.wav',22050], ['audio_1.wav',44100], ['audio_2.wav',48000],],[['audio_0.wav',22050], ['audio_1.wav',44100], ['audio_2.wav',48000],]]
dicts = [{'audio_0.wav': 22050, 'audio_1.wav': 44100, 'audio_2.wav': 48000}, {'audio_3.wav': 16000, 'audio_4.wav': 96000, 'audio_5.wav': 8000}]
merged_dicts = {k:v for list_item in dicts for (k,v) in list_item.items()}
print(merged_dicts.items())
print(merged_dicts)
meta = {}
meta['LJSpeech'] = []
meta['LJSpeech'].append({"path": "audio_0.wav", "emotions": ['Neutral']})
meta['LJSpeech'].append({"path": "audio_1.wav", "emotions": ['Happy']})
meta['VCTK'] = []
meta['VCTK'].append({"path": "p249_001.wav", "emotions": ['Bored']})
meta['VCTK'].append({"path": "p249_002.wav", "emotions": ['Sleepy']})
seen = set()

x = [0,1,2,3]
x[0] = 4
print(x)
print("WaveFlow Modified 48.00Khz")
n_layers = 7
n_group = 50
kernel_w = 3
kernel_h = 2
h_dilation_cycle = 8

assert (kernel_w%2==1), 'kernel_w must be odd'
h_dilation = min(2**(n_layers-1),2**(h_dilation_cycle-1))
width = (2**(n_layers-1)) * (kernel_w-1) * n_group
height = h_dilation * (kernel_h-1)
print(' Receptive Width: ', width)
print('Receptive Height: ', height)

###################################
print("-"*40)######################
print("Default WaveFlow 22.05Khz")#
###################################

n_layers = 8
n_group = 8
kernel_w = 3
kernel_h = 3
h_dilation_cycle = 4

assert (kernel_w%2==1), 'kernel_w must be odd'
h_dilation = min(2**(n_layers-1),2**(h_dilation_cycle-1))
width = (2**(n_layers-1)) * (kernel_w-1) * n_group
height = h_dilation * (kernel_h-1)
print(' Receptive Width: ', width)
print('Receptive Height: ', height)
import torch
torch.arange(5)[[4,3,2,1,0],]
print("!?,.;:␤#-_'\"()[]\n")
"!?,.;:␤#-_'\"()[]\n"
import os
os.path.splitext(os.path.split("/media/cookie/Samsung PM961/TwiBot/CookiePPPTTS/CookieTTS/_1_preprocess/datasets/Clipper_MLP/Sliced Dialogue/FiM/S7/s7e23/00_19_55_Pinkie_Neutral__Oh, i can't believe you're willing to eat This terrible pie for me.wav")[-1])[-1]
print(
    os.path.splitext("/media/cookie/Samsung PM961/TwiBot/CookiePPPTTS/CookieTTS/_1_preprocess/datasets/Clipper_MLP/Sliced Dialogue/FiM/S7/s7e23/00_19_55_Pinkie_Neutral__Oh, i can't believe you're willing to eat This terrible pie for me..wav")[0]
)
print(
    os.path.splitext("/media/cookie/Samsung PM961/TwiBot/CookiePPPTTS/CookieTTS/_1_preprocess/datasets/Clipper_MLP/Sliced Dialogue/FiM/S7/s7e23/00_19_55_Pinkie_Neutral__Oh, i can't believe you're willing to eat This terrible pie for me..wav")[0].rstrip('.')
)
from glob import glob
file_arr = glob('E:\downloads\Clipper_MLP\**\*.flac', recursive=True)
file_dict = {x: (os.path.splitext(x)[0].rstrip('.')+os.path.splitext(x)[-1]) for x in file_arr if x != (os.path.splitext(x)[0].rstrip('.')+os.path.splitext(x)[-1])}
raise FileNotFoundError(f'audio file at "asdsa.wav" has no matching txt file.')
os.link(
    r"H:\TTCheckpoints\waveflow\7thHeightDilated\samples\906500-2020_06_28-19_46_50\00_10_25_Applejack_Neutral__They sounded mighty serious when hey threatened to run us out of Business.wav",
    r"E:\downloads\Littlepip\capp.wav"
)
_dict = {'1': 1, '2': 2}
for i, (key, value) in enumerate(_dict.items()):
    print(i, key, value)
'"asdipsapojdas"'.strip('"')
print(
    os.path.abspath('audio/blah.txt'),
    os.path.abspath('audio\\blah.txt'),
    sep='\n')<jupyter_output>G:\TwiBot\CookiePPPTTS\CookieTTS\scripts\audio\blah.txt
G:\TwiBot\CookiePPPTTS\CookieTTS\scripts\audio\blah.txt<jupyter_text>Montreal Forced Aligner Output Parsing<jupyter_code>text = """File type = "ooTextFile"
Object class = "TextGrid"

xmin = 0.0
xmax = 4.024125
tiers? <exists>
size = 2
item []:
	item [1]:
		class = "IntervalTier"
		name = "words"
		xmin = 0.0
		xmax = 4.024125
		intervals: size = 11
			intervals [1]:
				xmin = 0.000
				xmax = 0.320
				text = "it's"
			intervals [2]:
				xmin = 0.320
				xmax = 0.620
				text = "so"
			intervals [3]:
				xmin = 0.620
				xmax = 0.650
				text = ""
			intervals [4]:
				xmin = 0.650
				xmax = 1.030
				text = "empty"
			intervals [5]:
				xmin = 1.030
				xmax = 1.950
				text = "and"
			intervals [6]:
				xmin = 1.950
				xmax = 1.980
				text = ""
			intervals [7]:
				xmin = 1.980
				xmax = 2.330
				text = "quiet"
			intervals [8]:
				xmin = 2.330
				xmax = 3.000
				text = "and"
			intervals [9]:
				xmin = 3.000
				xmax = 3.310
				text = ""
			intervals [10]:
				xmin = 3.310
				xmax = 3.750
				text = "lonely"
			intervals [11]:
				xmin = 3.750
				xmax = 4.024125
				text = ""
	item [2]:
		class = "IntervalTier"
		name = "phones"
		xmin = 0.0
		xmax = 4.024125
		intervals: size = 30
			intervals [1]:
				xmin = 0.000
				xmax = 0.160
				text = "IH0"
			intervals [2]:
				xmin = 0.160
				xmax = 0.260
				text = "T"
			intervals [3]:
				xmin = 0.260
				xmax = 0.320
				text = "S"
			intervals [4]:
				xmin = 0.320
				xmax = 0.380
				text = "S"
			intervals [5]:
				xmin = 0.380
				xmax = 0.620
				text = "OW1"
			intervals [6]:
				xmin = 0.620
				xmax = 0.650
				text = "sp"
			intervals [7]:
				xmin = 0.650
				xmax = 0.770
				text = "EH1"
			intervals [8]:
				xmin = 0.770
				xmax = 0.950
				text = "M"
			intervals [9]:
				xmin = 0.950
				xmax = 1.000
				text = "T"
			intervals [10]:
				xmin = 1.000
				xmax = 1.030
				text = "IY0"
			intervals [11]:
				xmin = 1.030
				xmax = 1.060
				text = "AH0"
			intervals [12]:
				xmin = 1.060
				xmax = 1.550
				text = "N"
			intervals [13]:
				xmin = 1.550
				xmax = 1.950
				text = "D"
			intervals [14]:
				xmin = 1.950
				xmax = 1.980
				text = "sp"
			intervals [15]:
				xmin = 1.980
				xmax = 2.020
				text = "K"
			intervals [16]:
				xmin = 2.020
				xmax = 2.070
				text = "W"
			intervals [17]:
				xmin = 2.070
				xmax = 2.220
				text = "AY1"
			intervals [18]:
				xmin = 2.220
				xmax = 2.300
				text = "AH0"
			intervals [19]:
				xmin = 2.300
				xmax = 2.330
				text = "T"
			intervals [20]:
				xmin = 2.330
				xmax = 2.360
				text = "AH0"
			intervals [21]:
				xmin = 2.360
				xmax = 2.390
				text = "N"
			intervals [22]:
				xmin = 2.390
				xmax = 3.000
				text = "D"
			intervals [23]:
				xmin = 3.000
				xmax = 3.310
				text = "sp"
			intervals [24]:
				xmin = 3.310
				xmax = 3.360
				text = "L"
			intervals [25]:
				xmin = 3.360
				xmax = 3.460
				text = "OW1"
			intervals [26]:
				xmin = 3.460
				xmax = 3.560
				text = "N"
			intervals [27]:
				xmin = 3.560
				xmax = 3.630
				text = "L"
			intervals [28]:
				xmin = 3.630
				xmax = 3.750
				text = "IY0"
			intervals [29]:
				xmin = 3.750
				xmax = 4.000
				text = "sp"
			intervals [30]:
				xmin = 4.000
				xmax = 4.024125
				text = ""
"""
def get(text, word_phones, punc="!?,.;:␤#-_'\"()[]\n"):
    """Convert block of text into ARPAbet."""
    word_phones = [x for x in word_phones if len(x[0])]
    out = []
    for word in text.split(" "):
        end_chars = ''; start_chars = ''
        while any(elem in word for elem in punc) and len(word) > 1:
            if word[-1] in punc:
                end_chars = word[-1] + end_chars
                word = word[:-1]
            elif word[0] in punc:
                start_chars = start_chars + word[0]
                word = word[1:]
            else:
                break
        try:
            word = "{" + ' '.join(word_phones[0][1]) + "}"
            word_phones = word_phones[1:]
        except KeyError:
            pass
        out.append((start_chars + (word or '') + end_chars).rstrip())
    return ' '.join(out)


def get_arpa(quote, words, phonemes):
    #words = [x['text'] for x in words] # remove timing info
    #phonemes = [x['text'] for x in phonemes] # remove timing info
    
    # IH0-T-S-S-OW1-sp-EH1-M-T-IY0-AH0-N-D-sp-K-W-AY1-AH0-T-AH0-N-D-sp-L-OW1-N-L-IY0-sp-
    # it's-so--empty-and--quiet-and--lonely-
    # It's so empty, and quiet, and lonely.
    
    # matchup words and phonemes using the timing info
    words_tmp = words
    phonemes_tmp = phonemes
    word_phones = []
    word_phones.append([])
    loops=0
    while len(words_tmp) and len(phonemes_tmp):
        wstart = words_tmp[0]['start']
        wend = words_tmp[0]['end']
        wtext = words_tmp[0]['text']
        if phonemes_tmp[0]['start'] >= wstart and phonemes_tmp[0]['end'] <= wend:
            word_phones[-1].append(phonemes_tmp[0]['text'])
            phonemes_tmp = phonemes_tmp[1:]
        elif phonemes_tmp[0]['end'] > wend:
            word_phones.append([])
            words_tmp = words_tmp[1:]
        loops+=1
        if loops > 50:
            break
    
    # replace words in quote with aligned phonemes.
    word_phones = list(zip([x['text'] for x in words], word_phones))
    print(word_phones)
    arpa_quote = get(quote, word_phones)
    print(' [Original Text] ')
    print(quote)
    print(' [ARPAbet Text] ')
    print(arpa_quote)
    return arpa_quote

def load_TextGrid(text, quote=None):
    assert text.startswith('File type = "ooTextFile"\nObject class = "TextGrid"\n'), 'Unsupported TextGrid filetype'
    text = text.split("\n")
    _dict = {}
    clip_start = float(text[3].split("=")[-1])
    clip_end = float(text[4].split("=")[-1])
    words_start = float(text[11].split("=")[-1])
    words_end = float(text[12].split("=")[-1])
    
    # text relating to word information
    end_word_list = 14+(int(text[13].split("=")[-1])*4)
    word_list = text[14:end_word_list]
    words = []
    for i, line in enumerate(word_list):
        if i%4==0: # xmin
            word = {}
        elif i%4==1: # xmin
            word['start'] = float(line.split("=")[-1])
        elif i%4==2: # xmax
            word['end'] = float(line.split("=")[-1])
        elif i%4==3: # text
            word['text'] = line.split("=")[-1].strip().strip('"')
            words.append(word)
    
    # text relating to phoneme information
    phone_list = text[end_word_list:]
    phone_start = float(phone_list[3].split("=")[-1])
    phone_end = float(phone_list[4].split("=")[-1])
    end_phone_list = end_word_list+(int(phone_list[5].split("=")[-1])*4)
    phones = []
    for i, line in enumerate(phone_list[6:6+end_phone_list]):
        if i%4==0: # xmin
            phone = {}
        elif i%4==1: # xmin
            phone['start'] = float(line.split("=")[-1])
        elif i%4==2: # xmax
            phone['end'] = float(line.split("=")[-1])
        elif i%4==3: # text
            phone['text'] = line.split("=")[-1].strip().strip('"')
            phones.append(phone)
    
    if quote is not None:
        # use phonemes to create ARPAbet transcript.
        print('-'.join([x['text'] for x in phones]))
        print('-'.join([x['text'] for x in words]))
        print(quote)
        _dict['arpabet_quote'] = get_arpa(quote, words, phones)
        
    
    # collect together
    _dict['clip_start'] = clip_start
    _dict['clip_end'] = clip_end
    _dict['words_start'] = words_start
    _dict['words_end'] = words_end
    _dict['phone_start'] = words_start
    _dict['phone_end'] = words_end
    _dict['words'] = words
    _dict['phones'] = phones
    return _dict


quote = """It's so empty, and quiet, and lonely."""
_dict = load_TextGrid(text, quote=quote)
#print(_dict)
x = [[[0,1],['a','b']],]
print(x)
for (a,b),(c,d) in x:
    print(a,b,c,d)
THREADS = 2.1
-((-THREADS)//2)
# updating Dataset from local copy, since it'll take multiple days to download otherwise!

from glob import glob
import shutil
import os
os.chdir('H:\ClipperDatasetV2\SlicedDialogue')
out_dir = r'E:\downloads\Clipper_MLP\Sliced Dialogue'
print('Changed Directory. Searching for Files...')
files = [*glob('**/*.flac', recursive=True), *glob('**/*.txt', recursive=True)]
len_files = len(files)
for i, file in enumerate(files):
    outpath = os.path.join(out_dir, file)
    try:
        if not os.path.exists(os.path.dirname(outpath)):
            os.makedirs(os.path.dirname(outpath))
        if not os.path.exists(outpath):
            shutil.copyfile(file, outpath)
            print(f'{i:>6}/{len_files:<6}: {outpath}{" "*100}', end='\r')
        else:
            print(f'{i:>6}/{len_files:<6}: {"Skipped"}{" "*100}', end='\r')
    except:
        pass
del files, len_files

os.chdir(out_dir)
files = glob('**/*.wav', recursive=True)
len_files = len(files)
for i, file in enumerate(files):
    print(f'{i:>6}/{len_files:<6}: {file}{" "*100}', end='\r')
    os.unlink(file)
os.chdir(out_dir)
files = glob('**/*.flac', recursive=True)
len_files = len(files)
for i, file in enumerate(files):
    if os.path.exists(os.path.splitext(file)[0]+'..flac'):
        os.unlink(file)
    print(f'{i:>6}/{len_files:<6}: {file}{" "*100}', end='\r')
import torch
x = torch.rand(5,5)
print(x.mean()/2)
print((x/2).mean())
[print(1000/x) for x in range(1,1000) if 1000/x == 1000//x]
from glob import glob
import os
for fpath in glob(r"G:\TwiBot\CookiePPPTTS\CookieTTS\_1_preprocess\datasets\Blaze the Cat\**\*__*", recursive=True):
    print(fpath)
    #if not os.path.isdir(fpath):
    #    os.rename(fpath, fpath.replace(' ','_'))
%%timeit
x = torch.rand(8,160,750, device='cuda')
%%timeit
y = x
%%timeit
y = x = torch.rand(8,160,750, device='cuda')
print('\n'.join([str(x) for x in list(file_dict.items())[0:100]]))
z = [[0,1,2],[3,4,5]]
for x in y for y in z:
    print(x)<jupyter_output><empty_output><jupyter_text>1 - Load Checkpoint<jupyter_code>waveflow_path = r"H:\TTCheckpoints\waveflow\4thLargeKernels\best_val_model"
checkpoint = torch.load(waveflow_path)
state_dict = checkpoint['model']
print( "  |  ".join([key for key in state_dict.keys()])  )<jupyter_output>alpha  |  speaker_embed.weight  |  cond_layers.0.bias  |  cond_layers.0.weight_g  |  cond_layers.0.weight_v  |  cond_layers.1.bias  |  cond_layers.1.weight_g  |  cond_layers.1.weight_v  |  cond_layers.2.bias  |  cond_layers.2.weight_g  |  cond_layers.2.weight_v  |  WN.0.WN.in_layers.0.0.bias  |  WN.0.WN.in_layers.0.0.weight_g  |  WN.0.WN.in_layers.0.0.weight_v  |  WN.0.WN.in_layers.0.1.bias  |  WN.0.WN.in_layers.0.1.weight_g  |  WN.0.WN.in_layers.0.1.weight_v  |  WN.0.WN.in_layers.1.0.bias  |  WN.0.WN.in_layers.1.0.weight_g  |  WN.0.WN.in_layers.1.0.weight_v  |  WN.0.WN.in_layers.1.1.bias  |  WN.0.WN.in_layers.1.1.weight_g  |  WN.0.WN.in_layers.1.1.weight_v  |  WN.0.WN.in_layers.2.0.bias  |  WN.0.WN.in_layers.2.0.weight_g  |  WN.0.WN.in_layers.2.0.weight_v  |  WN.0.WN.in_layers.2.1.bias  |  WN.0.WN.in_layers.2.1.weight_g  |  WN.0.WN.in_layers.2.1.weight_v  |  WN.0.WN.in_layers.3.0.bias  |  WN.0.WN.in_layers.3.0.weight_g  |  WN.0.WN.in_layers.3.0.weight_v  |  WN.0.WN.in_layers.3.1.bias [...]<jupyter_text>2 - Increase size of selected Layers<jupyter_code>print( "\n".join([f"{key:32}| {list(state_dict[key].shape)}" for key in state_dict.keys() if all(x in key for x in ('in_layers',))])  )
state_dict['WN.0.WN.in_layers.0.0.weight_g'].shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18651070763500932, 'fraction_numerical': 0.06872672253258845, 'mean_word_length': 2.846239928379588, 'pattern_counts': {'":': 36, '<': 66, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '386864', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 8137, 'n_tokens_neox': 6950, 'n_words': 1313, 'path': 'CookieTTS/scripts/Progressively Grow WaveFlow.ipynb', 'repo_name': 'AstraliteHeart/cookietts', 'size': '17208'}