Skip to content

Instantly share code, notes, and snippets.

@nobonobo
Created January 11, 2012 01:39
Show Gist options
  • Save nobonobo/1592436 to your computer and use it in GitHub Desktop.
Save nobonobo/1592436 to your computer and use it in GitHub Desktop.
AT620用 リングトーンファイルジェネレータ
#!/usr/bin/python
# encoding: utf-8
import sys
import os
import struct
import sunau
import wave
from StringIO import StringIO
def GenHeaderForAT620(size):
prefix = '+<_>)<(>*<&>^<%>$<#>@<!>~<`>|<{>}>[,].winline'
postfix= '_PHONE_RING1001'
return ''.join([prefix, struct.pack('>l', size), postfix])
def ConvertFile(fpath_inp, fpath_out):
print fpath_inp , '->', fpath_out
fpath, ext = os.path.splitext(fpath_inp)
if ext.lower() in ['.au']:
wave_inp = sunau.open(fpath_inp)
else:
wave_inp = wave.open(fpath_inp)
buff = StringIO()
wav_out = sunau.open(buff, 'w')
wav_out.setnchannels(wave_inp.getnchannels())
wav_out.setsampwidth(wave_inp.getsampwidth())
wav_out.setframerate(wave_inp.getframerate())
wav_out.setcomptype('ULAW', 'CCITT G.711 u-law')
wav_out.writeframes(wave_inp.readframes(wave_inp.getnframes()))
wav_out.close()
fp = open(fpath_out, 'wb')
fp.write(GenHeaderForAT620(buff.len))
fp.write(buff.getvalue())
fp.close()
if __name__=='__main__':
argv = sys.argv[1:]
ConvertFile(*argv[:2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment