From b53bd801ec9d27eb8c98dc286cf288be72f6e7ef Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sun, 7 Apr 2024 17:32:45 -0400 Subject: soxdial: add silence between dial strings, implement dialtone. --- soxdial | 62 +++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 21 deletions(-) (limited to 'soxdial') 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, B<--length> I - -Sets the time each digit's tones are played. Default is 0.25. - =item B<-o> I, B<--output> I 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, B<--length> I + +Sets the time each digit's tones are played. Default is 0.25. + =item B<-d> I, B<--delay> I 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(); -- cgit v1.2.3