| 3 | import os |
| 4 | |
| 5 | def create_dataset(data_dir="./data", repeat_count=2000, output_name="zh_lora_dataset"): |
| 6 | data_path = Path(data_dir) |
| 7 | all_examples = [] |
| 8 | |
| 9 | for song_path in data_path.glob("*.mp3"): |
| 10 | prompt_path = str(song_path).replace(".mp3", "_prompt.txt") |
| 11 | lyric_path = str(song_path).replace(".mp3", "_lyrics.txt") |
| 12 | try: |
| 13 | assert os.path.exists(prompt_path), f"Prompt file {prompt_path} does not exist." |
| 14 | assert os.path.exists(lyric_path), f"Lyrics file {lyric_path} does not exist." |
| 15 | with open(prompt_path, "r", encoding="utf-8") as f: |
| 16 | prompt = f.read().strip() |
| 17 | |
| 18 | with open(lyric_path, "r", encoding="utf-8") as f: |
| 19 | lyrics = f.read().strip() |
| 20 | |
| 21 | keys = song_path.stem |
| 22 | example = { |
| 23 | "keys": keys, |
| 24 | "filename": str(song_path), |
| 25 | "tags": prompt.split(", "), |
| 26 | "speaker_emb_path": "", |
| 27 | "norm_lyrics": lyrics, |
| 28 | "recaption": {} |
| 29 | } |
| 30 | all_examples.append(example) |
| 31 | except AssertionError as e: |
| 32 | continue |
| 33 | |
| 34 | # repeat specified times |
| 35 | ds = Dataset.from_list(all_examples * repeat_count) |
| 36 | ds.save_to_disk(output_name) |
| 37 | |
| 38 | import argparse |
| 39 | |