Add extract.py step to extract voices from streamwaves/streamvoice

This commit is contained in:
Vsevolod Kremianskii 2021-04-15 08:46:28 +07:00
parent 5a534bfcfa
commit e8a9179760
2 changed files with 29 additions and 2 deletions

View file

@ -35,6 +35,7 @@ steps = {
"extract_modules": True,
"extract_dialog": True,
"extract_textures": True,
"extract_voices": True,
"convert_to_json": False,
"convert_to_tga": False,
"convert_to_ascii_pth": False,
@ -139,6 +140,28 @@ def extract_dialog(game_dir, extract_dir):
except PermissionError:
pass
def extract_voices(game_dir, extract_dir):
# Create destination directory if it does not exist
dest_dir = os.path.join(extract_dir, "voices")
if not os.path.exists(dest_dir):
os.mkdir(dest_dir)
# Extract audio files from streamwaves/streamvoice
voices_dir = os.path.join(game_dir, "streamwaves")
if not os.path.exists(voices_dir):
voices_dir = os.path.join(game_dir, "streamvoice")
if os.path.exists(voices_dir):
for f in glob.glob("{}/**".format(voices_dir), recursive=True):
_, extension = os.path.splitext(f)
if extension == ".wav":
unwrapped_path = os.path.join(dest_dir, os.path.basename(f))
try:
shutil.copyfile(f, unwrapped_path)
except PermissionError:
pass
def convert_to_json(extract_dir):
CONVERTIBLE_EXT = [
".2da",
@ -156,6 +179,7 @@ def convert_to_json(extract_dir):
print("Converting {} to JSON...".format(f))
run_subprocess(["reone-tools", "--to-json", f])
def convert_to_tga(extract_dir):
for f in glob.glob("{}/**/*.tpc".format(extract_dir), recursive=True):
filename, _ = os.path.splitext(f)
@ -199,6 +223,9 @@ if steps["extract_textures"]:
if steps["extract_dialog"]:
extract_dialog(game_dir, extract_dir)
if steps["extract_voices"]:
extract_voices(game_dir, extract_dir)
if steps["convert_to_json"]:
convert_to_json(extract_dir)

View file

@ -17,7 +17,7 @@ if not os.path.exists(wav_dir):
raise RuntimeError("WAV directory does not exist")
def is_suitable_text(text):
def is_trainable_text(text):
return not (text.startswith("[") and text.endswith("]"))
@ -60,7 +60,7 @@ def get_lines_from_dlg(obj, speaker, tlk_strings):
textstrref = int(entry["Text|12"].split("|")[0])
if textstrref != -1:
text = tlk_strings[textstrref][1]
if voresref and (not voresref in uniq_sound) and is_suitable_text(text):
if voresref and (not voresref in uniq_sound) and is_trainable_text(text):
wav_filename = os.path.join(wav_dir, voresref + ".wav")
if os.path.exists(wav_filename):
lines.append("{}|{}|0\n".format(wav_filename, clear_text(text)))