Skip to content

Instantly share code, notes, and snippets.

@valmcc
Last active July 10, 2022 03:13
Show Gist options
  • Select an option

  • Save valmcc/7a252be88aea1f4ae66623b78adc31e6 to your computer and use it in GitHub Desktop.

Select an option

Save valmcc/7a252be88aea1f4ae66623b78adc31e6 to your computer and use it in GitHub Desktop.
Extracts all sound effect files for Animal Crossing New Horizons
# Extracts .bars files (like in Animal crossing New Horizons) into .bwav files
# (These are for sound effects)
# Place in your /Sound/Resource folder, it will then convert all the .bars files to .bwav files (output to /output_bwav)
# run with "python .\bwavbarextract.py"
# Tested with Python 3.8.2 on Windows 10
# By Valer (3/May/2020) (valmcc)
import glob
import os
import re
bars_list = glob.glob('./*.bars')
list_len = len(bars_list)
print(list_len,"bars files to convert...")
output_folder = "output_bwav"
print ("outputting to", output_folder)
BWAV_search_bytes = b'\x42\x57\x41\x56'
i = 1
for filename in bars_list:
# open file
print('File',i,"/",list_len,' converting bars file:',filename)
with open(filename, 'rb') as f:
bars = f.read()
# how many bwavs are in there in this bar file?
# search for all occurances of the search bytes
matches = []
curpos = 0
pattern = re.compile(BWAV_search_bytes)
while True:
m = pattern.search(bars[curpos:])
if m is None: break
matches.append(curpos + m.start())
curpos += m.end()
# for each of these matches extract a bwav
matches = [None, *matches, None]
print(len(matches),"bwavs found inside bars file...")
bwav_no = 0
for prev, cur, nxt in zip(matches, matches[1:], matches[2:]):
output = bars[cur:nxt]
output_filename = filename[:-5]
try:
os.mkdir("./" + output_folder)
except:
pass
output_filepath = "./" + output_folder + "/" + output_filename[2:] + "_" + str(bwav_no)
with open(output_filepath+".bwav", "wb") as f:
f.write(output)
bwav_no += 1
i += 1
print('Done! Press Enter to exit.')
input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment