Skip to content

Instantly share code, notes, and snippets.

@tera3939
Created February 5, 2017 07:42
Show Gist options
  • Save tera3939/980b4ede73165ad815644a85c7580044 to your computer and use it in GitHub Desktop.
Save tera3939/980b4ede73165ad815644a85c7580044 to your computer and use it in GitHub Desktop.
バイナリをwavに変換するやつ
# -*-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