mrfakename commited on
Commit
04e5c28
1 Parent(s): 3ce666d

Sync from GitHub repo

Browse files

This Space is synced from the GitHub repo: https://github.com/SWivid/F5-TTS. Please submit contributions to the Space there

Dockerfile CHANGED
@@ -10,14 +10,17 @@ RUN set -x \
10
  && apt-get update \
11
  && apt-get -y install wget curl man git less openssl libssl-dev unzip unar build-essential aria2 tmux vim \
12
  && apt-get install -y openssh-server sox libsox-fmt-all libsox-fmt-mp3 libsndfile1-dev ffmpeg \
 
13
  && rm -rf /var/lib/apt/lists/* \
14
  && apt-get clean
15
-
16
  WORKDIR /workspace
17
 
18
  RUN git clone https://github.com/SWivid/F5-TTS.git \
19
  && cd F5-TTS \
20
- && pip install -e .[eval]
 
 
21
 
22
  ENV SHELL=/bin/bash
23
 
 
10
  && apt-get update \
11
  && apt-get -y install wget curl man git less openssl libssl-dev unzip unar build-essential aria2 tmux vim \
12
  && apt-get install -y openssh-server sox libsox-fmt-all libsox-fmt-mp3 libsndfile1-dev ffmpeg \
13
+ && apt-get install librdmacm1 libibumad3 librdmacm-dev libibverbs1 libibverbs-dev ibverbs-utils ibverbs-providers \
14
  && rm -rf /var/lib/apt/lists/* \
15
  && apt-get clean
16
+
17
  WORKDIR /workspace
18
 
19
  RUN git clone https://github.com/SWivid/F5-TTS.git \
20
  && cd F5-TTS \
21
+ && git submodule update --init --recursive \
22
+ && sed -i '7iimport sys\nsys.path.append(os.path.dirname(os.path.abspath(__file__)))' src/third_party/BigVGAN/bigvgan.py \
23
+ && pip install -e . --no-cache-dir
24
 
25
  ENV SHELL=/bin/bash
26
 
src/f5_tts/train/README.md CHANGED
@@ -13,6 +13,9 @@ python src/f5_tts/train/datasets/prepare_emilia.py
13
 
14
  # Prepare the Wenetspeech4TTS dataset
15
  python src/f5_tts/train/datasets/prepare_wenetspeech4tts.py
 
 
 
16
  ```
17
 
18
  ### 2. Create custom dataset with metadata.csv
 
13
 
14
  # Prepare the Wenetspeech4TTS dataset
15
  python src/f5_tts/train/datasets/prepare_wenetspeech4tts.py
16
+
17
+ # Prepare the LibriTTS dataset
18
+ python src/f5_tts/train/datasets/prepare_libritts.py
19
  ```
20
 
21
  ### 2. Create custom dataset with metadata.csv
src/f5_tts/train/datasets/prepare_libritts.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ sys.path.append(os.getcwd())
5
+
6
+ import json
7
+ from concurrent.futures import ProcessPoolExecutor
8
+ from importlib.resources import files
9
+ from pathlib import Path
10
+ from tqdm import tqdm
11
+ import soundfile as sf
12
+ from datasets.arrow_writer import ArrowWriter
13
+
14
+
15
+ def deal_with_audio_dir(audio_dir):
16
+ sub_result, durations = [], []
17
+ vocab_set = set()
18
+ audio_lists = list(audio_dir.rglob("*.wav"))
19
+
20
+ for line in audio_lists:
21
+ text_path = line.with_suffix(".normalized.txt")
22
+ text = open(text_path, "r").read().strip()
23
+ duration = sf.info(line).duration
24
+ if duration < 0.4 or duration > 30:
25
+ continue
26
+ sub_result.append({"audio_path": str(line), "text": text, "duration": duration})
27
+ durations.append(duration)
28
+ vocab_set.update(list(text))
29
+ return sub_result, durations, vocab_set
30
+
31
+
32
+ def main():
33
+ result = []
34
+ duration_list = []
35
+ text_vocab_set = set()
36
+
37
+ # process raw data
38
+ executor = ProcessPoolExecutor(max_workers=max_workers)
39
+ futures = []
40
+
41
+ for subset in tqdm(SUB_SET):
42
+ dataset_path = Path(os.path.join(dataset_dir, subset))
43
+ [
44
+ futures.append(executor.submit(deal_with_audio_dir, audio_dir))
45
+ for audio_dir in dataset_path.iterdir()
46
+ if audio_dir.is_dir()
47
+ ]
48
+ for future in tqdm(futures, total=len(futures)):
49
+ sub_result, durations, vocab_set = future.result()
50
+ result.extend(sub_result)
51
+ duration_list.extend(durations)
52
+ text_vocab_set.update(vocab_set)
53
+ executor.shutdown()
54
+
55
+ # save preprocessed dataset to disk
56
+ if not os.path.exists(f"{save_dir}"):
57
+ os.makedirs(f"{save_dir}")
58
+ print(f"\nSaving to {save_dir} ...")
59
+
60
+ with ArrowWriter(path=f"{save_dir}/raw.arrow") as writer:
61
+ for line in tqdm(result, desc="Writing to raw.arrow ..."):
62
+ writer.write(line)
63
+
64
+ # dup a json separately saving duration in case for DynamicBatchSampler ease
65
+ with open(f"{save_dir}/duration.json", "w", encoding="utf-8") as f:
66
+ json.dump({"duration": duration_list}, f, ensure_ascii=False)
67
+
68
+ # vocab map, i.e. tokenizer
69
+ with open(f"{save_dir}/vocab.txt", "w") as f:
70
+ for vocab in sorted(text_vocab_set):
71
+ f.write(vocab + "\n")
72
+
73
+ print(f"\nFor {dataset_name}, sample count: {len(result)}")
74
+ print(f"For {dataset_name}, vocab size is: {len(text_vocab_set)}")
75
+ print(f"For {dataset_name}, total {sum(duration_list)/3600:.2f} hours")
76
+
77
+
78
+ if __name__ == "__main__":
79
+ max_workers = 36
80
+
81
+ tokenizer = "char" # "pinyin" | "char"
82
+
83
+ SUB_SET = ["train-clean-100", "train-clean-360", "train-other-500"]
84
+ dataset_dir = "<SOME_PATH>/LibriTTS"
85
+ dataset_name = f"LibriTTS_{'_'.join(SUB_SET)}_{tokenizer}".replace("train-clean-", "").replace("train-other-", "")
86
+ save_dir = str(files("f5_tts").joinpath("../../")) + f"/data/{dataset_name}"
87
+ print(f"\nPrepare for {dataset_name}, will save to {save_dir}\n")
88
+ main()
89
+
90
+ # For LibriTTS_100_360_500_char, sample count: 354218
91
+ # For LibriTTS_100_360_500_char, vocab size is: 78
92
+ # For LibriTTS_100_360_500_char, total 554.09 hours