Skip to content

Instantly share code, notes, and snippets.

@biggestsonicfan
Created June 14, 2023 02:35
Show Gist options
  • Save biggestsonicfan/b32c2fc695b168152f2028757c55be2b to your computer and use it in GitHub Desktop.
Save biggestsonicfan/b32c2fc695b168152f2028757c55be2b to your computer and use it in GitHub Desktop.
Extract .wav data from .srcd files
import os
import sys
import argparse
parser = argparse.ArgumentParser(description='Extract *.wav files from *.srcd files.')
parser.add_argument('-i', dest='input', type=str, help='Input directory of *.srcd files.', required=True)
parser.add_argument('-o', dest='output', type=str, help='Ouput directory of *.wav files. (Subdirectory "wav" in input used by default)')
def main():
args = parser.parse_args()
if args.input:
if os.path.isdir(str(args.input)):
srcd_list = [f for f in os.listdir(args.input) if f.endswith('.srcd')]
if len(srcd_list) > 0:
for audio in srcd_list:
file = os.path.join(str(args.input), audio)
wave_path = os.path.join(str(args.input), "wav")
if args.output:
if os.path.isdir(str(args.output)):
wave_path = str(args.output)
else:
print("Output directory specified is not valid, using default path " + wave_path)
with open(file, "rb") as audio_data:
audio_data.seek(int('0x52',base=16))
wave_len_bytes = audio_data.read(4)
wave_len = int.from_bytes(wave_len_bytes, byteorder='little', signed = True) + 8
audio_data.seek(int('0x4E',base=16))
wave_data = audio_data.read(wave_len)
if os.path.exists(wave_path) == False:
os.makedirs(wave_path)
wave_file = os.path.join(wave_path, audio.replace('.srcd','.wav'))
with open(wave_file, 'wb') as wave:
wave.write(wave_data)
print("Successfully extracted " + file + " to " + wave_file)
else:
print("Unable to find *.srcd files in directory " + str(args.input))
else:
print("Unable to find directory " + str(args.input))
try:
main()
except:
parser.print_help()
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment