Wav Dump exampleΒΆ

Demonstration script. Dumps audio from the timeline to a WAV file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python

################################################################################
#
# wavdump.py
#
# Version: 1.000
#
# Author: Gwynne Reddick
#
################################################################################

import traceback, wave

def main():
    inpoint = lx.eval('time.range current in:?')
    outpoint = lx.eval('time.range current out:?')
    asvc = lx.service.AudioAnim()
    aud = asvc.Preview(inpoint, outpoint)

    nchannels = aud.Channels()
    duration = aud.Duration()
    freq = aud.Frequency()
    atype = aud.Type()
    nframes = 16 * 2 * duration

    storage = aud.Data()
    storage.setType('b')
    storage.setSize(freq * nchannels * (atype / 8) * duration)
    buf = str(bytearray(storage.get()))

    wout = wave.open(r'C:\Data\wavout.wav', 'wb')
    wout.setparams((nchannels,(atype / 8),freq,nframes,'NONE', 'not compressed'))
    wout.writeframesraw(buf)
    wout.writeframes('')
    wout.close()


if __name__ == '__main__':
    try:
        main()
    except:
        lx.out(traceback.format_exc())