Created
August 8, 2023 14:59
-
-
Save rniwase/6f430e676c59175591f3388cd73acdd3 to your computer and use it in GitHub Desktop.
バイナリファイル内に含まれるRIFFフォーマットを検索・抽出してWAVファイルとして出力する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open("inputfile", "rb") as f: | |
s = f.read() | |
idx = -1 | |
count = -1 | |
while True: | |
idx = s.find(b"RIFF", idx + 1) | |
if idx == -1: | |
break | |
if s[idx+8:idx+12] != b"WAVE": | |
continue | |
fsize = int.from_bytes(s[idx+4:idx+8], "big") + 8 | |
if fsize < 64: | |
continue | |
count += 1 | |
print(fsize) | |
with open("out/{:0>2}.wav".format(count), "wb") as f: | |
f.write(s[idx:idx+fsize]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment