File size: 1,669 Bytes
24303c9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import os.path
import json
import numpy as np
import pandas as pd
import torch
from datasets import Dataset
from matplotlib import pyplot as plt
from tqdm import tqdm
phoneme_path = 'dump/phoneme.npy'
flist_path = 'dump/train_files_gs.list'
phoneme_data = np.load(phoneme_path, allow_pickle=True).item()
all_paths = [line.strip() for line in open(flist_path).readlines()]
all_paths = set(all_paths)
phoneme_data = {k: v for k, v in tqdm(phoneme_data.items()) if k in all_paths}
print(len(phoneme_data))
def generate_data():
for k, v in phoneme_data.items():
itemname = k
code_path = itemname.replace(".wav", ".code.pt")
if not os.path.exists(code_path):
continue
code = torch.load(code_path).squeeze(0)
dur = code.shape[0] / 10
spk_emb_path = itemname.replace(".wav", ".spk.npy")
if not os.path.exists(spk_emb_path):
print( f'spk_emb_path {spk_emb_path} not exists for {itemname}\n\n\n\n\n\n\n\n\n')
continue
spk_emb = np.load(spk_emb_path)
if spk_emb.shape != (256, ):
print( f'spk_emb shape {spk_emb.shape} not correct for {itemname}\n\n\n\n\n\n\n\n\n')
if dur > 100:
print(f'dur {dur} too long for {itemname}\n\n\n\n\n\n\n\n')
yield {"item_name": itemname, "codes": code, 'phoneme': v, 'length': dur, 'spk_emb': spk_emb}
dataset = Dataset.from_generator(generate_data)
print(dataset)
test_samples = 10
split_dataset = dataset.train_test_split(test_size=test_samples/len(dataset), shuffle=True)
split_dataset.save_to_disk('dump/phone_semantic_dataset')
print("average duration", np.mean(dataset['length'])) |