Created
February 5, 2017 07:42
-
-
Save tera3939/980b4ede73165ad815644a85c7580044 to your computer and use it in GitHub Desktop.
バイナリを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
# -*-encoding:utf-8-*- | |
import sys | |
import wave | |
def bin2wav(filedata, filename, channels=2, sampwidth=2, framerate=14400, nframe=0, comptype='NONE', compname='not compressed'): | |
w = wave.Wave_write(filename) | |
p = (channels, sampwidth, framerate, nframe, comptype, compname) | |
w.setparams(p) | |
w.writeframes(filedata) | |
w.close() | |
if __name__ == '__main__': | |
f = open(sys.argv[1] ,'rb') | |
filename = sys.argv[1].split('.')[0] + '.wav' | |
data = f.read() | |
nframe = len(data) // 2 | |
bin2wav(filedata=data, filename=filename, nframe=nframe) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment