1 """Convert "arbitrary" sound files to AIFF (Apple and SGI's audio format).
3 Input may be compressed.
4 Uncompressed file type may be AIFF, WAV, VOC, 8SVX, NeXT/Sun, and others.
5 An exception is raised if the file is not of a recognized type.
6 Returned filename is either the input filename or a temporary filename;
7 in the latter case the caller must ensure that it is removed.
8 Other temporary files used are removed by the function.
19 t
.append('sox -t au - -t aiff -r 8000 -', '--')
22 # XXX The following is actually sub-optimal.
23 # XXX The HCOM sampling rate can be 22k, 22k/2, 22k/3 or 22k/4.
24 # XXX We must force the output sampling rate else the SGI won't play
25 # XXX files sampled at 5.5k or 7.333k; however this means that files
26 # XXX sampled at 11k are unnecessarily expanded.
27 # XXX Similar comments apply to some other file types.
29 t
.append('sox -t hcom - -t aiff -r 22050 -', '--')
33 t
.append('sox -t voc - -t aiff -r 11025 -', '--')
37 t
.append('sox -t wav - -t aiff -', '--')
41 t
.append('sox -t 8svx - -t aiff -r 16000 -', '--')
45 t
.append('sox -t sndt - -t aiff -r 16000 -', '--')
49 t
.append('sox -t sndr - -t aiff -r 16000 -', '--')
52 uncompress
= pipes
.Template()
53 uncompress
.append('uncompress', '--')
56 error
= 'toaiff.error' # Exception
62 ret
= _toaiff(filename
, temps
)
73 def _toaiff(filename
, temps
):
74 if filename
[-2:] == '.Z':
75 fname
= tempfile
.mktemp()
77 sts
= uncompress
.copy(filename
, fname
)
79 raise error
, filename
+ ': uncomress failed'
83 ftype
= sndhdr
.whathdr(fname
)
85 ftype
= ftype
[0] # All we're interested in
87 if type(msg
) == type(()) and len(msg
) == 2 and \
88 type(msg
[0]) == type(0) and type(msg
[1]) == type(''):
90 if type(msg
) <> type(''):
92 raise error
, filename
+ ': ' + msg
95 if ftype
== None or not table
.has_key(ftype
):
97 filename
+ ': unsupported audio file type ' + `ftype`
98 temp
= tempfile
.mktemp()
100 sts
= table
[ftype
].copy(fname
, temp
)
102 raise error
, filename
+ ': conversion to aiff failed'