| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| import argparse |
| import logging |
| import torch |
| from tqdm import tqdm |
| import numpy as np |
|
|
| import torch.distributed as distr |
| import pathlib |
| from distributed import init_distributed_context |
|
|
| import logging |
| logger = logging.getLogger(__name__) |
| import os |
| import sys |
| import re |
| import glob |
|
|
| from huggingface_hub import snapshot_download |
|
|
| sys.path.insert(0,'/apdcephfs_nj7/share_303172353/ggyzhang/projects/Amphion') |
|
|
| from models.vc.vevo.vevo_utils import * |
|
|
|
|
|
|
| def single_job(infer_pipeline, wav_fp): |
| tokens = inference_pipeline.extract_contentstyle_codes(wav_fp=wav_fp) |
| return tokens.squeeze(0).numpy() |
|
|
|
|
| def extract_speech_token(args, rank, world_size): |
| wavs = glob.glob(f'{args.wav_dir}/**/*.wav',recursive=True) |
| device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu") |
| |
| local_dir = snapshot_download( |
| repo_id="amphion/Vevo", |
| repo_type="model", |
| cache_dir="./ckpts/Vevo", |
| allow_patterns=["tokenizer/vq8192/*"], |
| ) |
| content_style_tokenizer_ckpt_path = os.path.join(local_dir, "tokenizer/vq8192") |
| fmt_cfg_path = "./models/vc/vevo/config/Vq8192ToMels.json" |
| |
| inference_pipeline = Vevo_ContentStyleTokenizer_Pipeline( |
| content_style_tokenizer_ckpt_path=content_style_tokenizer_ckpt_path, |
| fmt_cfg_path=fmt_cfg_path, |
| device=device, |
| ) |
|
|
| print(len(wavs)) |
| for i in tqdm(range(rank, len(wavs), world_size)): |
| wav_fp = wavs[i] |
| item_name = os.path.basename(wav_fp).split('.')[0] |
| new_fp = os.path.dirname(wav_fp).replace('LRS3','LRS3_speech_token') |
| save_path = f'{new_fp}/{item_name}.npy' |
| |
| |
| try: |
| speech_token = single_job(wav_fp) |
| except: |
| print('error!!!!!!!!',wav_fp) |
| continue |
| if len(speech_token)==0: |
| continue |
| os.makedirs(new_fp,exist_ok=True) |
| np.save(f'{new_fp}/{item_name}.npy',speech_token) |
|
|
| def main(args): |
| context = init_distributed_context(args.distributed_port) |
| logger.info(f"Distributed context {context}") |
|
|
| n_gpus = torch.cuda.device_count() |
| with torch.cuda.device(context.local_rank % n_gpus): |
| extract_speech_token(args, context.rank, context.world_size) |
|
|
| if context.world_size > 1: |
| distr.barrier() |
|
|
| if __name__ == "__main__": |
| parser = argparse.ArgumentParser() |
| parser.add_argument("--wav_dir", type=str) |
| parser.add_argument("--distributed_port", type=int, default=58564) |
| args = parser.parse_args() |
|
|
| main(args) |