aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-04-08 15:03:54 -0400
committerB. Watson <urchlay@slackware.uk>2024-04-08 15:03:54 -0400
commit238238077ab3b0b5120052bc320d9986614e0d1c (patch)
tree75dd83942bb1bca6a2bb1a31d2529b89ec06f3ad
parent98597af3d5fcdd0c6acddcb7e7c92c811aedc8ea (diff)
downloadmisc-scripts-238238077ab3b0b5120052bc320d9986614e0d1c.tar.gz
soxdial: add --dialtone-type for different countries.
-rwxr-xr-xsoxdial35
1 files changed, 32 insertions, 3 deletions
diff --git a/soxdial b/soxdial
index fc09bca..b004fc3 100755
--- a/soxdial
+++ b/soxdial
@@ -128,10 +128,15 @@ 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> B<--dialtone> [ I<sec> | I<millisec>B<ms> ]
+=item B<-t>, B<--dialtone> [ I<sec> | I<millisec>B<ms> ]
Play I<sec> (or I<millisec> ms) of dialtone before the next dial string.
+=item B<-D>, B<--dialtone-type> [ I<us> | I<uk> | I<fr> | I<eu> | I<jp> ]
+
+Set the type of dialtone to be played by B<-d>, B<--dialtone>. Default
+is B<us>.
+
=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.
@@ -222,6 +227,7 @@ $bits = 8;
$encoding = "-eun";
$rate = 8000;
$output = "-d";
+$dialtone_type = "us";
sub letter2number {
my $ret;
@@ -317,8 +323,28 @@ sub dialtone_subcmd {
warn "$SELF: ignoring invalid --dialtone argument.\n";
return;
}
- warn "$SELF: adding $sec sec of dial tone.\n" if $verbose;
- return "sox -n -b$bits $encoding -r$rate -c1 -traw - synth $sec sine 350 sine 440";
+ warn "$SELF: adding $sec sec of dial tone, type '$dialtone_type'.\n" if $verbose;
+ my $cmd = "sox -n -b$bits $encoding -r$rate -c1 -traw - synth $sec ";
+ for($dialtone_type) {
+ /^us$/ && do { $cmd .= "sine 350 sine 440" };
+ /^uk$/ && do { $cmd .= "sine 350 sine 450" };
+ /^eu$/ && do { $cmd .= "sine 425" };
+ /^fr$/ && do { $cmd .= "sine 440" };
+ /^jp$/ && do { $cmd .= "sine 400" };
+ }
+
+ return $cmd;
+}
+
+# these are all the dialtone types I know about (or, that wikipedia knows about).
+sub set_dialtone_type {
+ my $type = shift || "";
+ $type = lc $type;
+ if($type !~ /^(?:us|uk|eu|fr|jp)$/) {
+ die "$SELF: invalid dialtone type '$type'.\n";
+ }
+ $dialtone_type = $type;
+ warn "$SELF: set dialtone type to '$type'.\n" if $verbose;
}
# final sox command, to which we pipe all the others.
@@ -365,6 +391,7 @@ if(!@ARGV) {
exit 1;
}
+# this is a big ugly mess. should be refactored. works, though.
for ($argc = 0; $argc < @ARGV; $argc++) {
$_ = $ARGV[$argc];
@@ -425,6 +452,8 @@ for ($argc = 0; $argc < @ARGV; $argc++) {
$pausetime = parse_sec($ARGV[++$argc]);
warn "$SELF: comma delay set to '$pausetime'\n" if $verbose;
die "$SELF: invalid --comma argument.\n" unless $pausetime > 0;
+ } elsif(/^--?(?:D|dialtone-type)$/) {
+ set_dialtone_type($ARGV[++$argc]);
} elsif(/^--?(?:t|dialtone)$/) {
push @sox_subcmds, dialtone_subcmd(parse_sec($ARGV[++$argc]));
} elsif(/^--?s(?:ilence)?$/) {