- Timestamp:
- Sep 16, 2017, 12:36:42 PM (7 years ago)
- 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:
- c95062b
- Parents:
- 9a52962
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/cut.py
r9a52962 rb02d52f 8 8 import argparse 9 9 10 def parse_args():10 def aubio_cut_parser(): 11 11 usage = "usage: %s [options] -i soundfile" % sys.argv[0] 12 12 usage += "\n help: %s -h" % sys.argv[0] … … 133 133 action="store_false", dest="verbose", default=True, 134 134 help="be quiet") 135 args = parser.parse_args() 136 if not args.source_file and not args.source_file2: 137 sys.stderr.write("Error: no file name given\n") 138 parser.print_help() 139 sys.exit(1) 140 elif args.source_file2 is not None: 141 args.source_file = args.source_file2 142 return args 143 144 def main(): 145 options = parse_args() 146 135 return parser 136 137 138 def _cut_analyze(options): 147 139 source_file = options.source_file 148 140 hopsize = options.hopsize … … 151 143 source_file = options.source_file 152 144 145 # analyze pass 153 146 from aubio import onset, tempo, source 154 147 155 148 s = source(source_file, samplerate, hopsize) 156 if samplerate == 0: samplerate = s.get_samplerate() 149 if samplerate == 0: 150 samplerate = s.get_samplerate() 151 options.samplerate = samplerate 157 152 158 153 if options.beat: … … 171 166 timestamps = [] 172 167 total_frames = 0 173 # analyze pass174 168 while True: 175 169 samples, read = s() … … 180 174 if read < hopsize: break 181 175 del s 182 # print some info 176 return timestamps, total_frames 177 178 def _cut_slice(options, timestamps): 179 # cutting pass 183 180 nstamps = len(timestamps) 184 duration = float (total_frames) / float(samplerate) 185 info = 'found %(nstamps)d timestamps in %(source_file)s' % locals() 186 info += ' (total %(duration).2fs at %(samplerate)dHz)\n' % locals() 187 sys.stderr.write(info) 188 189 # cutting pass 190 if options.cut and nstamps > 0: 181 if nstamps > 0: 191 182 # generate output files 192 183 from aubio.slicing import slice_source_at_stamps … … 203 194 timestamps_end = [t for t in timestamps[1 + options.cut_until_nslices:]] 204 195 timestamps_end += [ 1e120 ] * (options.cut_until_nslices + 1) 205 slice_source_at_stamps(source_file, timestamps, timestamps_end = timestamps_end, 196 slice_source_at_stamps(options.source_file, 197 timestamps, timestamps_end = timestamps_end, 206 198 output_dir = options.output_directory, 207 samplerate = samplerate) 208 209 # print some info 210 duration = float (total_frames) / float(samplerate) 211 info = 'created %(nstamps)d slices from %(source_file)s' % locals() 212 info += ' (total %(duration).2fs at %(samplerate)dHz)\n' % locals() 199 samplerate = options.samplerate) 200 201 def main(): 202 parser = aubio_cut_parser() 203 options = parser.parse_args() 204 if not options.source_file and not options.source_file2: 205 sys.stderr.write("Error: no file name given\n") 206 parser.print_help() 207 sys.exit(1) 208 elif options.source_file2 is not None: 209 options.source_file = options.source_file2 210 211 # analysis 212 timestamps, total_frames = _cut_analyze(options) 213 214 # print some info 215 duration = float (total_frames) / float(options.samplerate) 216 base_info = '%(source_file)s' % {'source_file': options.source_file} 217 base_info += ' (total %(duration).2fs at %(samplerate)dHz)\n' % \ 218 {'duration': duration, 'samplerate': options.samplerate} 219 220 info = "found %d timestamps in " % len(timestamps) 221 info += base_info 222 sys.stderr.write(info) 223 224 if options.cut: 225 _cut_slice(options, timestamps) 226 info = "created %d slices from " % len(timestamps) 227 info += base_info 213 228 sys.stderr.write(info)
Note: See TracChangeset
for help on using the changeset viewer.