12 if ARGF.argv.count != 2
13 puts "Usage: #{$PROGRAM_NAME} input.wav output.wav"
21 '-af', "loudnorm='I=#{target_il}:LRA=#{target_lra}:tp=#{target_tp}:print_format=json'",
25 _stdin, _stdout, stderr, wait_thr = Open3.popen3(*ff_cmd)
27 if wait_thr.value.success?
28 stats = JSON.parse(stderr.read.lines[-12, 12].join)
29 loudnorm_string = 'loudnorm='
30 loudnorm_string += 'print_format=summary:'
31 loudnorm_string += 'linear=true:'
32 loudnorm_string += "I=#{target_il}:"
33 loudnorm_string += "LRA=#{target_lra}:"
34 loudnorm_string += "tp=#{target_tp}:"
35 loudnorm_string += "measured_I=#{stats['input_i']}:"
36 loudnorm_string += "measured_LRA=#{stats['input_lra']}:"
37 loudnorm_string += "measured_tp=#{stats['input_tp']}:"
38 loudnorm_string += "measured_thresh=#{stats['input_thresh']}:"
39 loudnorm_string += "offset=#{stats['target_offset']}"
49 '-af', loudnorm_string,
53 _stdin, _stdout, stderr, wait_thr = Open3.popen3(*ff_cmd)
55 if wait_thr.value.success?
56 puts stderr.read.lines[-12, 12].join