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.
10 from warnings
import warnpy3k
11 warnpy3k("the toaiff module has been removed in Python 3.0", stacklevel
=2)
19 __all__
= ["error", "toaiff"]
24 t
.append('sox -t au - -t aiff -r 8000 -', '--')
27 # XXX The following is actually sub-optimal.
28 # XXX The HCOM sampling rate can be 22k, 22k/2, 22k/3 or 22k/4.
29 # XXX We must force the output sampling rate else the SGI won't play
30 # XXX files sampled at 5.5k or 7.333k; however this means that files
31 # XXX sampled at 11k are unnecessarily expanded.
32 # XXX Similar comments apply to some other file types.
34 t
.append('sox -t hcom - -t aiff -r 22050 -', '--')
38 t
.append('sox -t voc - -t aiff -r 11025 -', '--')
42 t
.append('sox -t wav - -t aiff -', '--')
46 t
.append('sox -t 8svx - -t aiff -r 16000 -', '--')
50 t
.append('sox -t sndt - -t aiff -r 16000 -', '--')
54 t
.append('sox -t sndr - -t aiff -r 16000 -', '--')
57 uncompress
= pipes
.Template()
58 uncompress
.append('uncompress', '--')
61 class error(Exception):
68 ret
= _toaiff(filename
, temps
)
79 def _toaiff(filename
, temps
):
80 if filename
[-2:] == '.Z':
81 (fd
, fname
) = tempfile
.mkstemp()
84 sts
= uncompress
.copy(filename
, fname
)
86 raise error
, filename
+ ': uncompress failed'
90 ftype
= sndhdr
.whathdr(fname
)
92 ftype
= ftype
[0] # All we're interested in
94 if type(msg
) == type(()) and len(msg
) == 2 and \
95 type(msg
[0]) == type(0) and type(msg
[1]) == type(''):
97 if type(msg
) != type(''):
99 raise error
, filename
+ ': ' + msg
102 if ftype
is None or not ftype
in table
:
103 raise error
, '%s: unsupported audio file type %r' % (filename
, ftype
)
104 (fd
, temp
) = tempfile
.mkstemp()
107 sts
= table
[ftype
].copy(fname
, temp
)
109 raise error
, filename
+ ': conversion to aiff failed'