8 def apply_filter(path, target):
9 # open input file, get its samplerate
10 s = aubio.source(path)
11 samplerate = s.samplerate
13 # create an A-weighting filter
14 f = aubio.digital_filter(7)
15 f.set_a_weighting(samplerate)
18 o = aubio.sink(target, samplerate)
25 filtered_samples = f(samples)
27 o(filtered_samples, read)
35 duration = total_frames / float(samplerate)
36 input_str = "input: {:s} ({:.2f} s, {:d} Hz)"
37 output_str = "output: {:s}, A-weighting filtered ({:d} frames total)"
38 print(input_str.format(s.uri, duration, samplerate))
39 print(output_str.format(o.uri, total_frames))
41 if __name__ == '__main__':
42 usage = "{:s} <input_file> [output_file]".format(sys.argv[0])
43 if not 1 < len(sys.argv) < 4:
47 input_path = sys.argv[1]
48 basename = os.path.splitext(os.path.basename(input_path))[0] + ".wav"
49 output_path = "filtered_" + basename
51 input_path, output_path = sys.argv[1:]
53 apply_filter(input_path, output_path)