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-11 16:52:47 -0400
commitc9db22c6a349befefb22dad06c9f82779726f73e (patch)
tree965e22cf9d58aed141953e9615cc28037777c045
parentc69331c7735a9bdd1343583a37a9c99a0e719c71 (diff)
downloadsoxdial-c9db22c6a349befefb22dad06c9f82779726f73e.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);
}
}