Changeset 896c3a8 for python/lib


Ignore:
Timestamp:
Sep 12, 2017, 4:51:41 PM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
Children:
ee123a0
Parents:
67ee29f
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/lib/aubio/cmd.py

    r67ee29f r896c3a8  
    9797    parser_add_verbose_help(subparser)
    9898    subparser.set_defaults(process=process_melbands)
     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)
    99109
    100110    return parser
     
    368378        fmt_out += ' '.join(["% 9.7f" % f for f in res.tolist()])
    369379        sys.stdout.write(fmt_out + '\n')
     380
     381class 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')
    370416
    371417def main():
Note: See TracChangeset for help on using the changeset viewer.