History

python/lib/aubio/cmd.py: add quiet subcommand (closes #124)

Paul Brossier committed 9 years ago

Commit 896c3a81 parent 67ee29f1 file · +46 −0Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/lib/aubio/cmd.py+46−0
@@ -97,6 +97,16 @@ def aubio_parser(): · 96 unmodified lines
9797 parser_add_verbose_help(subparser)
9898 subparser.set_defaults(process=process_melbands)
9999
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+
100110 return parser
101111
102112 def parser_add_input(parser):
@@ -368,6 +378,42 @@ class process_melbands(default_process): · 265 unmodified lines
368378 fmt_out += ' '.join(["% 9.7f" % f for f in res.tolist()])
369379 sys.stdout.write(fmt_out + '\n')
370380
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+
371417 def main():
372418 parser = aubio_parser()
373419 args = parser.parse_args()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t