aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-04-08 03:22:21 -0400
committerB. Watson <urchlay@slackware.uk>2024-04-08 03:22:21 -0400
commit98597af3d5fcdd0c6acddcb7e7c92c811aedc8ea (patch)
treebb3cfd467c4e7a9defe636c7dd68e1e12ead0d00
parent005d1ddcb66028d86b8a8ab2a04dc7ce69bf296b (diff)
downloadmisc-scripts-98597af3d5fcdd0c6acddcb7e7c92c811aedc8ea.tar.gz
soxdial: add -s/--silence, normalize volume.
-rwxr-xr-xsoxdial35
1 files changed, 25 insertions, 10 deletions
diff --git a/soxdial b/soxdial
index ea24b13..fc09bca 100755
--- a/soxdial
+++ b/soxdial
@@ -128,9 +128,13 @@ Disables extended touchtone pad keys A, B, C, and D; re-enables
letter-to-number conversions. This is the default; this option exists
to turn off a prior B<-x>, B<--extended> option.
-=item B<-t> I<sec>, B<--dialtone> I<sec>
+=item B<-t> B<--dialtone> [ I<sec> | I<millisec>B<ms> ]
-Play I<sec> of dialtone.
+Play I<sec> (or I<millisec> ms) of dialtone before the next dial string.
+
+=item B<-s>, B<--silence> [ I<sec> | I<millisec>B<ms> ]
+
+Play I<sec> (or I<millisec> ms) of silence before the next dial string.
=back
@@ -144,7 +148,8 @@ phones (e.g. A through C convert to 2, D through F are 3, etc).
Q and Z weren't present on classic phones, but they will be converted
to 7 and 9, respectively (like modern cell phones).
-To add an extra delay between digits, use a comma.
+To add an extra delay between digits, use a comma (and see the B<-c>,
+B<--comma> option to set the length of the delay).
To play the extra DTMF tones for the extended 16-digit keypad (which has
A, B, C, and D keys), use the B<-x>, B<--extended> option. This disables
@@ -268,13 +273,16 @@ sub add_digit {
# ...plays 2 sec of dialtone followed by 2 sec of DTMF key 1. Change the -d
# to 1.wav to save to a file. Prefix it with -rXXXX -sX if needed.
-# each dial string (or dialtone) creates a subcommand. they get executed in a
-# subshell, writing raw audio to stdout, and the final sox command reads all
-# the audio from its stdin. looks like:
+# each dial string (or --dialtone, or --silence) creates a
+# subcommand. they get executed in a subshell, writing raw audio
+# to stdout, and the final sox command reads all the audio from its
+# stdin. looks like:
# ( <subcommand1> ; <subcommand2> ; ... ) | sox <final output args>
+# --norm is needed because otherwise, the volume decreases as the number of
+# digits (tones for "synth") goes up. --norm=-3 helps avoid clipping.
sub make_sox_subcmd {
- my $cmd = "sox -n -b$bits $encoding -r$rate -c1 -traw - ";
+ my $cmd = "sox -n -b$bits $encoding -r$rate -c1 -traw - --norm=-3 ";
my $synth = " synth $digittime ";
my $delay = "delay ";
@@ -294,8 +302,13 @@ sub make_sox_subcmd {
# used to add the silence after the last digit in a dial string
sub silence_subcmd {
- warn "$SELF: adding $intertime sec silence at end of dial string.\n" if $verbose;
- return "sox -n -b$bits $encoding -r$rate -c1 -traw - trim 0 $intertime";
+ my $s = shift;
+ if(!defined $s || ($s + 0) <= 0) {
+ warn "$SELF: ignoring invalid --silence argument.\n";
+ return;
+ }
+ warn "$SELF: adding $s sec silence.\n" if $verbose;
+ return "sox -n -b$bits $encoding -r$rate -c1 -traw - trim 0 $s";
}
sub dialtone_subcmd {
@@ -414,6 +427,8 @@ for ($argc = 0; $argc < @ARGV; $argc++) {
die "$SELF: invalid --comma argument.\n" unless $pausetime > 0;
} elsif(/^--?(?:t|dialtone)$/) {
push @sox_subcmds, dialtone_subcmd(parse_sec($ARGV[++$argc]));
+ } elsif(/^--?s(?:ilence)?$/) {
+ push @sox_subcmds, silence_subcmd(parse_sec($ARGV[++$argc]));
} else {
warn "$SELF: start dial string '$_'\n" if $verbose;
for (split "", $_) {
@@ -428,7 +443,7 @@ for ($argc = 0; $argc < @ARGV; $argc++) {
}
warn "$SELF: end dial string '$_'\n" if $verbose;
push @sox_subcmds, make_sox_subcmd();
- push @sox_subcmds, silence_subcmd();
+ push @sox_subcmds, silence_subcmd($intertime);
}
}