Upload 7 files
Browse files- .gitattributes +2 -0
- bg3.ndjson +3 -0
- compute_statistics.py +35 -0
- create_dataset.py +47 -0
- english.loca.json +3 -0
- requirements.in +2 -0
- requirements.txt +8 -0
- speaker_stats.json +0 -0
.gitattributes
CHANGED
|
@@ -53,3 +53,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
bg3.ndjson filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
english.loca.json filter=lfs diff=lfs merge=lfs -text
|
bg3.ndjson
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5737710b1d1fa0df83989d752f03dbd7b2443d44f2104ba5c2a1eab89c61326a
|
| 3 |
+
size 42257474
|
compute_statistics.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
def get_sample():
|
| 4 |
+
with open("bg3.ndjson", "r") as bg3_f:
|
| 5 |
+
for line in bg3_f:
|
| 6 |
+
yield json.loads(line.strip())
|
| 7 |
+
|
| 8 |
+
def main():
|
| 9 |
+
speaker_stats = {}
|
| 10 |
+
total_duration = 0.0
|
| 11 |
+
total_num_samples = 0
|
| 12 |
+
for metadata in get_sample():
|
| 13 |
+
total_num_samples+=1
|
| 14 |
+
duration = metadata["duration"]
|
| 15 |
+
total_duration += duration
|
| 16 |
+
spk_id = metadata["spk_id"]
|
| 17 |
+
if spk_id not in speaker_stats.keys():
|
| 18 |
+
speaker_stats[spk_id] = dict(num_samples=0, total_duration=0)
|
| 19 |
+
speaker_stats[spk_id]["num_samples"] += 1
|
| 20 |
+
speaker_stats[spk_id]["total_duration"] += duration
|
| 21 |
+
|
| 22 |
+
for spk_id in speaker_stats.keys():
|
| 23 |
+
speaker_stats[spk_id]["mean_duration"] = speaker_stats[spk_id]["total_duration"]/speaker_stats[spk_id]["num_samples"]
|
| 24 |
+
|
| 25 |
+
speaker_stats["global"] = dict(
|
| 26 |
+
num_samples=total_num_samples,
|
| 27 |
+
total_duration=total_duration,
|
| 28 |
+
mean_duration=total_duration/len(speaker_stats)
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
print(json.dumps(speaker_stats, indent=2))
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if __name__=="__main__":
|
| 35 |
+
main()
|
create_dataset.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import re
|
| 3 |
+
from os import getenv
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from tqdm import tqdm
|
| 6 |
+
from soundfile import SoundFile
|
| 7 |
+
|
| 8 |
+
ROOT = getenv("BG3_VOICE")
|
| 9 |
+
assert ROOT is not None, "Please set the BG3_VOICE environment variable to the directory Voice.pak was unpacked in."
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def main():
|
| 13 |
+
Path("./wav/").mkdir(exist_ok=True)
|
| 14 |
+
root_path = Path(ROOT)
|
| 15 |
+
sound_path = root_path/"Mods/Gustav/Localization/English/Soundbanks"
|
| 16 |
+
with open("english.loca.json", "r") as loca_f:
|
| 17 |
+
uid_to_txt = json.load(loca_f)
|
| 18 |
+
with open("bg3.ndjson", "w") as bg3_f:
|
| 19 |
+
for file in tqdm(list(sound_path.glob(f"*.wav"))):
|
| 20 |
+
file_path=file.resolve()
|
| 21 |
+
try:
|
| 22 |
+
contentuid = re.search(r"h.*(?=\.wem)", file_path.stem).group()
|
| 23 |
+
except AttributeError:
|
| 24 |
+
continue
|
| 25 |
+
try:
|
| 26 |
+
text = uid_to_txt[contentuid]
|
| 27 |
+
except KeyError:
|
| 28 |
+
continue
|
| 29 |
+
text = re.sub(r"\(\[.*\]\)", "", text)
|
| 30 |
+
Path("wav/"+file_path.name).hardlink_to(file_path)
|
| 31 |
+
snd_file = SoundFile(str(file_path), "r")
|
| 32 |
+
sample = dict(
|
| 33 |
+
name=file_path.name,
|
| 34 |
+
text=text,
|
| 35 |
+
spk_id=file_path.name.replace(
|
| 36 |
+
f"_{contentuid}.wem.wav",""
|
| 37 |
+
),
|
| 38 |
+
is_effect=bool(re.match(r"v[0-9]", text)),
|
| 39 |
+
samplerate=snd_file.samplerate,
|
| 40 |
+
duration=snd_file.frames/snd_file.samplerate,
|
| 41 |
+
n_channels=snd_file.channels,
|
| 42 |
+
)
|
| 43 |
+
json.dump(sample, bg3_f)
|
| 44 |
+
bg3_f.write("\n")
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
main()
|
english.loca.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6c8a5aafd8072130ce2deab024a597017449de8245b397dcd11dac73c8fe4dd9
|
| 3 |
+
size 23934356
|
requirements.in
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
soundfile
|
| 2 |
+
tqdm
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file was autogenerated by uv via the following command:
|
| 2 |
+
# uv pip compile requirements.in -o requirements.txt
|
| 3 |
+
cffi==1.16.0
|
| 4 |
+
# via soundfile
|
| 5 |
+
pycparser==2.22
|
| 6 |
+
# via cffi
|
| 7 |
+
soundfile==0.12.1
|
| 8 |
+
tqdm==4.66.4
|
speaker_stats.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|