source: python/demos/demo_simple_robot_voice.py @ b6230d8

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since b6230d8 was 4120fbc, checked in by Paul Brossier <piem@piem.org>, 9 years ago

python/demos: python3 and double precision compatibility

  • Property mode set to 100755
File size: 1015 bytes
RevLine 
[7175ed4]1#! /usr/bin/env python
[e693b6c]2
3import sys
4from aubio import source, sink, pvoc
5
6if __name__ == '__main__':
[0c6e3b0]7    if len(sys.argv) < 2:
[4120fbc]8        print('usage: %s <inputfile> <outputfile>' % sys.argv[0])
[0c6e3b0]9        sys.exit(1)
10    samplerate = 44100
11    f = source(sys.argv[1], samplerate, 256)
12    g = sink(sys.argv[2], samplerate)
13    total_frames, read = 0, 256
[e693b6c]14
[0c6e3b0]15    win_s = 512                          # fft size
[4120fbc]16    hop_s = win_s // 2                   # hop size
[0c6e3b0]17    pv = pvoc(win_s, hop_s)              # phase vocoder
[e693b6c]18
[0c6e3b0]19    while read:
20        samples, read = f()
21        spectrum = pv(samples)           # compute spectrum
22        #spectrum.norm *= .8             # reduce amplitude a bit
23        spectrum.phas[:] = 0.            # zero phase
24        new_samples = pv.rdo(spectrum)   # compute modified samples
25        g(new_samples, read)             # write to output
26        total_frames += read
[e693b6c]27
[4120fbc]28    format_str = "read {:d} samples from {:s}, written to {:s}"
29    print(format_str.format(total_frames, f.uri, g.uri))
Note: See TracBrowser for help on using the repository browser.