-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio.py
More file actions
261 lines (206 loc) · 7.72 KB
/
audio.py
File metadata and controls
261 lines (206 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/env python3
# =========================================================
# Unreal Engine Wwise Audio Extract Helper
# Author: Abyssrte
#
# Note:
# This script automates audio extraction from UE Wwise
# .wem and .bnk files using existing open-source tools.
#
# Credits:
# - ww2ogg by hcs64
# - vgmstream project
# - FFmpeg
#
# This is a helper script, not a re-implementation
# of the original tools.
# =========================================================
# ================= AUTO DEPENDENCY CHECK =================
import sys
import os
import subprocess
# ANSI COLORS (NO COLORAMA)
RED = "\033[91m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
RESET = "\033[0m"
BOLD = "\033[1m"
def clear_screen():
os.system("clear" if os.name != "nt" else "cls")
def _silent_ok(cmd):
return subprocess.run(
cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
).returncode == 0
def ensure_python_pkg(pkg):
try:
__import__(pkg)
return True
except ImportError:
print(f"{YELLOW}[+]{RESET} Installing Python package: {BOLD}{pkg}{RESET}")
subprocess.run(
[sys.executable, "-m", "pip", "install", pkg]
)
try:
__import__(pkg)
print(f"{GREEN}[✓]{RESET} {pkg} installed")
return True
except ImportError:
return False
def ensure_system_pkg(cmd, pkg):
if _silent_ok(["which", cmd]):
return True
print(f"{YELLOW}[+]{RESET} Installing system package: {BOLD}{pkg}{RESET}")
subprocess.run(
["pkg", "install", "-y", pkg]
)
return _silent_ok(["which", cmd])
def check_dependencies():
failed = False
if not ensure_python_pkg("colorama"):
print(f"{RED}[✗]{RESET} Failed to install colorama")
failed = True
if not ensure_system_pkg("vgmstream-cli", "vgmstream"):
print(f"{RED}[✗]{RESET} Failed to install vgmstream")
failed = True
if not ensure_system_pkg("ffmpeg", "ffmpeg"):
print(f"{RED}[✗]{RESET} Failed to install ffmpeg")
failed = True
if failed:
print(f"\n{RED}{BOLD}[!] Dependency installation failed. Fix manually.{RESET}")
sys.exit(1)
check_dependencies()
clear_screen()
# =========================================================
import sys
import os
import subprocess
import random
from colorama import Fore, Style, init
init(autoreset=True)
# ---------- CONFIG ----------
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
TOOLS_DIR = os.path.join(BASE_DIR, "tools")
fuck = os.path.join(TOOLS_DIR, "audio")
CODEBOOK = os.path.join(TOOLS_DIR, "packed_codebooks_aoTuV_603.bin")
OUTPUT_DIR = os.path.join(BASE_DIR, "UE_Audio")
BANNER_COLOR = "brightred"
# ----------------------------
BRIGHT_COLORS = {
"brightred": Fore.LIGHTRED_EX,
"brightgreen": Fore.LIGHTGREEN_EX,
"brightyellow": Fore.LIGHTYELLOW_EX,
"brightblue": Fore.LIGHTBLUE_EX,
"brightmagenta": Fore.LIGHTMAGENTA_EX,
"brightcyan": Fore.LIGHTCYAN_EX,
"brightwhite": Fore.LIGHTWHITE_EX,
}
def print_banner():
print()
banner_text = [
" █ ██ ▓█████ ▄▄▄ █ ██ ▓█████▄ ██▓ ▒█████ ",
" ██ ▓██▒▓█ ▀ ▒████▄ ██ ▓██▒▒██▀ ██▌▓██▒▒██▒ ██▒",
"▓██ ▒██░▒███ ▒██ ▀█▄ ▓██ ▒██░░██ █▌▒██▒▒██░ ██▒",
"▓▓█ ░██░▒▓█ ▄ ░██▄▄▄▄██ ▓▓█ ░██░░▓█▄ ▌░██░▒██ ██░",
"▒▒█████▓ ░▒████▒ ▓█ ▓██▒▒▒█████▓ ░▒████▓ ░██░░ ████▓▒░",
"░▒▓▒ ▒ ▒ ░░ ▒░ ░ ▒▒ ▓▒█░░▒▓▒ ▒ ▒ ▒▒▓ ▒ ░▓ ░ ▒░▒░▒░ ",
"░░▒░ ░ ░ ░ ░ ░ ▒ ▒▒ ░░░▒░ ░ ░ ░ ▒ ▒ ▒ ░ ░ ▒ ▒░ ",
" ░░░ ░ ░ ░ ░ ▒ ░░░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ▒ ",
" ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ",
]
color = BRIGHT_COLORS.get(BANNER_COLOR, Fore.LIGHTRED_EX)
for line in banner_text:
print(color + Style.BRIGHT + line)
print()
print(Fore.LIGHTGREEN_EX + Style.BRIGHT + "[Tool By :- Abyssrte]")
def usage():
print(Fore.LIGHTRED_EX + Style.BRIGHT + "[Unreal Engine Audio Extractor]")
print(Fore.LIGHTCYAN_EX + Style.BRIGHT + "USAGE:")
print(" python audio.py file.wem")
print(" python audio.py -bnk file.bnk\n")
print(Fore.LIGHTCYAN_EX + "NOTES:")
print(Fore.LIGHTYELLOW_EX +Style.BRIGHT + "Work Only .bnk file and .wem")
print(Fore.LIGHTYELLOW_EX +Style.BRIGHT + "Soon Replace .wem in .bnk file")
sys.exit(0)
def run_cmd(cmd, error_hint):
result = subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
if result.returncode != 0:
print(Fore.LIGHTRED_EX + Style.BRIGHT + "ERROR:")
print(result.stderr.strip())
print(Fore.LIGHTYELLOW_EX + Style.BRIGHT + "HOW TO FIX:")
print(error_hint)
sys.exit(1)
return result.stdout
def extract_bnk(bnk_file):
if not os.path.isfile(bnk_file):
print(Fore.LIGHTRED_EX + "ERROR: .bnk file not found")
sys.exit(1)
os.makedirs(OUTPUT_DIR, exist_ok=True)
meta = run_cmd(
["vgmstream-cli", "-m", bnk_file],
"vgmstream-cli not found. Install with: pkg install vgmstream"
)
stream_count = None
for line in meta.splitlines():
if "stream count:" in line:
stream_count = int(line.split(":")[1].strip())
break
if stream_count is None:
print(Fore.LIGHTRED_EX + "ERROR: Unable to detect stream count")
sys.exit(1)
base = os.path.splitext(os.path.basename(bnk_file))[0]
for i in range(stream_count):
out_wav = os.path.join(OUTPUT_DIR, f"{base}_{i}.wav")
run_cmd(
["vgmstream-cli", "-s", str(i), "-o", out_wav, bnk_file],
"Failed to extract audio stream"
)
print(Fore.LIGHTGREEN_EX + Style.BRIGHT + "SUCCESS:")
print(Fore.LIGHTGREEN_EX + f"Extracted {stream_count} audio files to {OUTPUT_DIR}/")
def extract_wem(wem_file):
if not os.path.isfile(wem_file):
print(Fore.LIGHTRED_EX + "ERROR: .wem file not found")
sys.exit(1)
if not os.path.isfile(fuck):
print(Fore.LIGHTRED_EX + "ERROR: audio tool not found")
sys.exit(1)
if not os.path.isfile(CODEBOOK):
print(Fore.LIGHTRED_EX + "ERROR: packed_codebooks file missing")
sys.exit(1)
os.makedirs(OUTPUT_DIR, exist_ok=True)
base = os.path.splitext(os.path.basename(wem_file))[0]
ogg_file = base + ".ogg"
wav_file = os.path.join(OUTPUT_DIR, base + ".wav")
run_cmd(
[fuck, wem_file, "--pcb", CODEBOOK],
"WEM file may be encrypted or unsupported"
)
run_cmd(
["ffmpeg", "-y", "-i", ogg_file, wav_file],
"FFmpeg not installed. Install with: pkg install ffmpeg"
)
if os.path.isfile(ogg_file):
try:
os.remove(ogg_file)
except:
pass
print(Fore.LIGHTGREEN_EX + Style.BRIGHT + "SUCCESS:")
print(Fore.LIGHTGREEN_EX + f"Audio extracted -> {wav_file}")
def main():
print_banner()
if len(sys.argv) == 1:
usage()
if sys.argv[1] == "-bnk":
if len(sys.argv) != 3:
usage()
extract_bnk(sys.argv[2])
return
extract_wem(sys.argv[1])
if __name__ == "__main__":
main()