ref: 896c3a8f0ac7884c46a86bc8f7b50e4e3a01ebf5
parent: 67ee29f4f5ea5f2611056e927756e370f6537c25
author: Paul Brossier <piem@piem.org>
date: Tue Sep 12 12:51:41 EDT 2017
python/lib/aubio/cmd.py: add quiet subcommand (closes #124)
--- a/python/lib/aubio/cmd.py
+++ b/python/lib/aubio/cmd.py
@@ -97,6 +97,16 @@
parser_add_verbose_help(subparser)
subparser.set_defaults(process=process_melbands)
+ # quiet subcommand
+ subparser = subparsers.add_parser('quiet',
+ help='')
+ parser_add_input(subparser)
+ parser_add_hop_size(subparser)
+ parser_add_silence(subparser)
+ parser_add_time_format(subparser)
+ parser_add_verbose_help(subparser)
+ subparser.set_defaults(process=process_quiet)
+
return parser
def parser_add_input(parser):
@@ -367,6 +377,42 @@
fmt_out = self.time2string(frames_read, samplerate)
fmt_out += ' '.join(["% 9.7f" % f for f in res.tolist()])
sys.stdout.write(fmt_out + '\n')
+
+class process_quiet(default_process):
+ def __init__(self, args):
+ self.args = args
+ valid_opts = ['hop_size', 'silence']
+ self.parse_options(args, valid_opts)
+ self.issilence = None
+ self.wassilence = 1
+
+ if args.silence is not None:
+ self.silence = args.silence
+ super(process_quiet, self).__init__(args)
+
+ def __call__(self, block):
+ if aubio.silence_detection(block, self.silence) == 1:
+ if self.wassilence == 1:
+ self.issilence = 1
+ else:
+ self.issilence = 2
+ self.wassilence = 1
+ else:
+ if self.wassilence == 0:
+ self.issilence = 0
+ else:
+ self.issilence = -1
+ self.wassilence = 0
+
+ def repr_res(self, res, frames_read, samplerate):
+ fmt_out = None
+ if self.issilence == -1:
+ fmt_out = "NOISY: "
+ if self.issilence == 2:
+ fmt_out = "QUIET: "
+ if fmt_out is not None:
+ fmt_out += self.time2string(frames_read, samplerate)
+ sys.stdout.write(fmt_out + '\n')
def main():
parser = aubio_parser()