aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-04-07 17:32:45 -0400
committerB. Watson <urchlay@slackware.uk>2024-04-07 17:32:45 -0400
commitb53bd801ec9d27eb8c98dc286cf288be72f6e7ef (patch)
treebb12487329ed4544fee6e8b22ee5f2a8b4fb0f9f
parent3a52e3435c530c0769cbfde42d4cd9332a56b588 (diff)
downloadmisc-scripts-b53bd801ec9d27eb8c98dc286cf288be72f6e7ef.tar.gz
soxdial: add silence between dial strings, implement dialtone.
-rwxr-xr-xsoxdial62
1 files changed, 41 insertions, 21 deletions
diff --git a/soxdial b/soxdial
index 29a66ee..a590df5 100755
--- a/soxdial
+++ b/soxdial
@@ -32,10 +32,6 @@ before any dial strings or dial options.
=over 4
-=item B<-l> I<sec>, B<--length> I<sec>
-
-Sets the time each digit's tones are played. Default is 0.25.
-
=item B<-o> I<output>, B<--output> I<output>
Write sox's output to a file, rather than playing it. The file format
@@ -86,6 +82,10 @@ dial strings, until the same option is seen again.
=over 4
+=item B<-l> I<sec>, B<--length> I<sec>
+
+Sets the time each digit's tones are played. Default is 0.25.
+
=item B<-d> I<sec>, B<--delay> I<sec>
Sets the delay between consecutive digits. Default is 0.1.
@@ -166,6 +166,7 @@ $pausetime = 0.5;
$digittime = 0.25;
$intertime = 0.1;
$bits = 8;
+$encoding = "-eun";
$rate = 8000;
$output = "-d";
@@ -191,10 +192,6 @@ sub letter2number {
# sox -n -d synth 0.25 sine 697 sine 1209 sine 770 sine 1477 delay 0 0 .35 .35 remix -
# ...plays DTMF 1 and 6, for 0.25 sec each, with a 0.10 sec delay between them.
-# ( sox -n -p synth 2 sine 350 sine 440; sox -n -p synth 2 sine 697 sine 1209 ) | sox -G -p -d
-# ...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.
-
sub add_digit {
my $d = shift;
if($d eq ',') {
@@ -219,11 +216,12 @@ sub add_digit {
warn "$SELF: added digit '$d', time now $time\n" if $verbose;
}
-sub make_sox_cmd {
- if($output eq '-') {
- $output = "-t raw $output";
- }
- my $cmd = "sox -n -b$bits -r$rate -c1 $output ";
+# ( sox -n -p synth 2 sine 350 sine 440; sox -n -p synth 2 sine 697 sine 1209 ) | sox -G -p -d
+# ...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.
+
+sub make_sox_subcmd {
+ my $cmd = "sox -n -b$bits $encoding -r$rate -c1 -traw - ";
my $synth = " synth $digittime ";
my $delay = "delay ";
@@ -236,7 +234,26 @@ sub make_sox_cmd {
$delay .= "$d $d ";
}
- return $cmd . $synth . $delay . " remix -";
+ $time = 0;
+ @freqs1 = @freqs2 = @delays = ();
+ return $cmd . $synth . $delay;
+}
+
+sub silence_subcmd {
+ return "sox -n -b$bits $encoding -r$rate -c1 -traw - trim 0 $intertime";
+}
+
+sub dialtone_subcmd {
+ return "sox -n -b$bits $encoding -r$rate -c1 -traw - synth $_[0] sine 350 sine 440";
+}
+
+sub make_sox_cmd {
+ if($output eq '-') {
+ $output = "-t raw $output";
+ }
+ my $cmd = "sox -traw -b$bits $encoding -r$rate -c1 - $output ";
+ my $subcmds = join(" ; ", @sox_subcmds);
+ return "( " . $subcmds . " ) | " . $cmd;
}
# main()
@@ -267,16 +284,17 @@ for ($argc = 0; $argc < @ARGV; $argc++) {
warn "$SELF: output set to '$output'\n" if $verbose;
} elsif(/^--?b(?:its)?$/) {
$bits = $ARGV[++$argc];
- if($bits != 8 && $bits != 16) {
+ if($bits == 8) {
+ $encoding = "-eun";
+ } elsif($bits == 16) {
+ $encoding = "-esig";
+ } else {
die "$SELF: bad -b/--bits, only 8 or 16 is allowed.\n";
}
warn "$SELF: bits set to '$bits'\n" if $verbose;
} elsif(/^--?r(?:ate)?$/) {
$rate = $ARGV[++$argc];
} elsif(/^--?l(?:ength)?$/) {
- if(@freqs1) {
- die "$SELF: can't change length after a dial string\n";
- }
$digittime = $ARGV[++$argc];
warn "$SELF: digittime set to '$digittime'\n" if $verbose;
} elsif(/^--?(?:x|extended)$/) {
@@ -292,7 +310,7 @@ for ($argc = 0; $argc < @ARGV; $argc++) {
$pausetime = $ARGV[++$argc];
warn "$SELF: comma delay set to '$pausetime'\n" if $verbose;
} elsif(/^--?(?:t|dialtone)$/) {
- die "$SELF: -t/--dialtone option not yet implemented.\n";
+ push @sox_subcmds, dialtone_subcmd($ARGV[++$argc]);
} else {
warn "$SELF: start dial string '$_'\n" if $verbose;
for (split "", $_) {
@@ -306,11 +324,13 @@ for ($argc = 0; $argc < @ARGV; $argc++) {
add_digit($digit);
}
warn "$SELF: end dial string '$_'\n" if $verbose;
+ push @sox_subcmds, make_sox_subcmd();
+ push @sox_subcmds, silence_subcmd();
}
}
-if(!@freqs1) {
- die "$SELF: no digits to dial.\n";
+if(!@sox_subcmds) {
+ die "$SELF: no digits or dialtone to generate.\n";
}
my $cmd = make_sox_cmd();