From c94f346207c70fbb3c7eef2776e8d165a07eeba1 Mon Sep 17 00:00:00 2001 From: Jerryuhoo Date: Thu, 6 Jan 2022 15:03:54 +0800 Subject: [PATCH] move link_wav.py to paddlespeech/t2s/exps/gan_vocoder/ move link_wav.py to paddlespeech/t2s/exps/gan_vocoder/ so that different vocoders can use one script. --- examples/csmsc/voc3/finetune.sh | 2 +- examples/csmsc/voc3/local/link_wav.py | 85 ------------------- examples/csmsc/voc5/finetune.sh | 2 +- .../t2s/exps/gan_vocoder}/link_wav.py | 1 - 4 files changed, 2 insertions(+), 88 deletions(-) delete mode 100644 examples/csmsc/voc3/local/link_wav.py rename {examples/csmsc/voc5/local => paddlespeech/t2s/exps/gan_vocoder}/link_wav.py (98%) diff --git a/examples/csmsc/voc3/finetune.sh b/examples/csmsc/voc3/finetune.sh index 1ff0f18a..ef2349f5 100755 --- a/examples/csmsc/voc3/finetune.sh +++ b/examples/csmsc/voc3/finetune.sh @@ -21,7 +21,7 @@ if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then fi if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then - python3 local/link_wav.py \ + python3 ${MAIN_ROOT}/paddlespeech/t2s/exps/gan_vocoder/link_wav.py \ --old-dump-dir=dump \ --dump-dir=dump_finetune fi diff --git a/examples/csmsc/voc3/local/link_wav.py b/examples/csmsc/voc3/local/link_wav.py deleted file mode 100644 index c81e0d4b..00000000 --- a/examples/csmsc/voc3/local/link_wav.py +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import argparse -import os -from operator import itemgetter -from pathlib import Path - -import jsonlines -import numpy as np - - -def main(): - # parse config and args - parser = argparse.ArgumentParser( - description="Preprocess audio and then extract features .") - - parser.add_argument( - "--old-dump-dir", - default=None, - type=str, - help="directory to dump feature files.") - parser.add_argument( - "--dump-dir", - type=str, - required=True, - help="directory to finetune dump feature files.") - args = parser.parse_args() - - old_dump_dir = Path(args.old_dump_dir).expanduser() - old_dump_dir = old_dump_dir.resolve() - dump_dir = Path(args.dump_dir).expanduser() - # use absolute path - dump_dir = dump_dir.resolve() - dump_dir.mkdir(parents=True, exist_ok=True) - - assert old_dump_dir.is_dir() - assert dump_dir.is_dir() - - for sub in ["train", "dev", "test"]: - # 把 old_dump_dir 里面的 *-wave.npy 软连接到 dump_dir 的对应位置 - output_dir = dump_dir / sub - output_dir.mkdir(parents=True, exist_ok=True) - results = [] - for name in os.listdir(output_dir / "raw"): - # 003918_feats.npy - utt_id = name.split("_")[0] - mel_path = output_dir / ("raw/" + name) - gen_mel = np.load(mel_path) - wave_name = utt_id + "_wave.npy" - wav = np.load(old_dump_dir / sub / ("raw/" + wave_name)) - os.symlink(old_dump_dir / sub / ("raw/" + wave_name), - output_dir / ("raw/" + wave_name)) - num_sample = wav.shape[0] - num_frames = gen_mel.shape[0] - wav_path = output_dir / ("raw/" + wave_name) - - record = { - "utt_id": utt_id, - "num_samples": num_sample, - "num_frames": num_frames, - "feats": str(mel_path), - "wave": str(wav_path), - } - results.append(record) - - results.sort(key=itemgetter("utt_id")) - - with jsonlines.open(output_dir / "raw/metadata.jsonl", 'w') as writer: - for item in results: - writer.write(item) - - -if __name__ == "__main__": - main() diff --git a/examples/csmsc/voc5/finetune.sh b/examples/csmsc/voc5/finetune.sh index 1ff0f18a..ef2349f5 100755 --- a/examples/csmsc/voc5/finetune.sh +++ b/examples/csmsc/voc5/finetune.sh @@ -21,7 +21,7 @@ if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then fi if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then - python3 local/link_wav.py \ + python3 ${MAIN_ROOT}/paddlespeech/t2s/exps/gan_vocoder/link_wav.py \ --old-dump-dir=dump \ --dump-dir=dump_finetune fi diff --git a/examples/csmsc/voc5/local/link_wav.py b/paddlespeech/t2s/exps/gan_vocoder/link_wav.py similarity index 98% rename from examples/csmsc/voc5/local/link_wav.py rename to paddlespeech/t2s/exps/gan_vocoder/link_wav.py index 4bab3d5e..5b24c87d 100644 --- a/examples/csmsc/voc5/local/link_wav.py +++ b/paddlespeech/t2s/exps/gan_vocoder/link_wav.py @@ -54,7 +54,6 @@ def main(): results = [] files = os.listdir(output_dir / "raw") for name in tqdm(files): - # 003918_feats.npy utt_id = name.split("_feats.npy")[0] mel_path = output_dir / ("raw/" + name) gen_mel = np.load(mel_path)