Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -97,6 +97,16 @@ def aubio_parser(): · 96 unmodified lines | |||
| 97 | parser_add_verbose_help(subparser) | 97 | parser_add_verbose_help(subparser) |
| 98 | subparser.set_defaults(process=process_melbands) | 98 | subparser.set_defaults(process=process_melbands) |
| 99 | 99 | ||
| 100 | # quiet subcommand | ||
| 101 | subparser = subparsers.add_parser('quiet', | ||
| 102 | help='') | ||
| 103 | parser_add_input(subparser) | ||
| 104 | parser_add_hop_size(subparser) | ||
| 105 | parser_add_silence(subparser) | ||
| 106 | parser_add_time_format(subparser) | ||
| 107 | parser_add_verbose_help(subparser) | ||
| 108 | subparser.set_defaults(process=process_quiet) | ||
| 109 | |||
| 100 | return parser | 110 | return parser |
| 101 | 111 | ||
| 102 | def parser_add_input(parser): | 112 | def parser_add_input(parser): |
| @@ -368,6 +378,42 @@ class process_melbands(default_process): · 265 unmodified lines | |||
| 368 | fmt_out += ' '.join(["% 9.7f" % f for f in res.tolist()]) | 378 | fmt_out += ' '.join(["% 9.7f" % f for f in res.tolist()]) |
| 369 | sys.stdout.write(fmt_out + '\n') | 379 | sys.stdout.write(fmt_out + '\n') |
| 370 | 380 | ||
| 381 | class process_quiet(default_process): | ||
| 382 | def __init__(self, args): | ||
| 383 | self.args = args | ||
| 384 | valid_opts = ['hop_size', 'silence'] | ||
| 385 | self.parse_options(args, valid_opts) | ||
| 386 | self.issilence = None | ||
| 387 | self.wassilence = 1 | ||
| 388 | |||
| 389 | if args.silence is not None: | ||
| 390 | self.silence = args.silence | ||
| 391 | super(process_quiet, self).__init__(args) | ||
| 392 | |||
| 393 | def __call__(self, block): | ||
| 394 | if aubio.silence_detection(block, self.silence) == 1: | ||
| 395 | if self.wassilence == 1: | ||
| 396 | self.issilence = 1 | ||
| 397 | else: | ||
| 398 | self.issilence = 2 | ||
| 399 | self.wassilence = 1 | ||
| 400 | else: | ||
| 401 | if self.wassilence == 0: | ||
| 402 | self.issilence = 0 | ||
| 403 | else: | ||
| 404 | self.issilence = -1 | ||
| 405 | self.wassilence = 0 | ||
| 406 | |||
| 407 | def repr_res(self, res, frames_read, samplerate): | ||
| 408 | fmt_out = None | ||
| 409 | if self.issilence == -1: | ||
| 410 | fmt_out = "NOISY: " | ||
| 411 | if self.issilence == 2: | ||
| 412 | fmt_out = "QUIET: " | ||
| 413 | if fmt_out is not None: | ||
| 414 | fmt_out += self.time2string(frames_read, samplerate) | ||
| 415 | sys.stdout.write(fmt_out + '\n') | ||
| 416 | |||
| 371 | def main(): | 417 | def main(): |
| 372 | parser = aubio_parser() | 418 | parser = aubio_parser() |
| 373 | args = parser.parse_args() | 419 | args = parser.parse_args() |