From 50c4513911aa12cb21d4c49a5f9f2050595ee8f2 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 12 Apr 2024 16:25:13 -0400 Subject: soxdial: add --sox option and SOX environment variable. --- soxdial | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/soxdial b/soxdial index fae3dda..b41d47d 100755 --- a/soxdial +++ b/soxdial @@ -127,6 +127,16 @@ error. Do not execute the generated B command. This option also enables B<-v>. +=item B<--sox> I + +Explicitly set the location of the sox binary. Useful if it's in a +nonstandard location. If this doesn't contain any slashes, B is +used to search for it. If it does contain slashes, it's used as a full +path (e.g. B<--sox /usr/local/audiostuff/sox/bin/sox>. + +This option does the same thing as the B environment variable, +but it will override the environment. + =back =head2 Dial Options @@ -256,6 +266,24 @@ The alternate names for B<0> (B<10>), B (B<11>), and B (B<12>) are not supported, since there's no way to tell an 11 from two 1's. +=head1 ENVIRONMENT + +=over 4 + +=item B + +By default, B is searched for in B. + +=item B + +Sets the path to the B executable. Same as the B<--sox> option, q.v. + +=item B, B, B, etc. + +These options affect B; see the B(1) man page for details. + +=back + =head1 NOTES B<1.> B works by iterating over the words on the command @@ -434,7 +462,7 @@ sub make_sox_subcmd { return ":" unless @freqs1; my $length = shift || $digittime; - my $cmd = "sox -n -b$bits $encoding -r$rate -c1 -traw - --norm=-3 "; + my $cmd = "$SOX -n -b$bits $encoding -r$rate -c1 -traw - --norm=-3 "; my $synth = " synth $length "; my $delay = "delay "; @@ -460,7 +488,7 @@ sub silence_subcmd { return; } warn "$SELF: adding $s sec silence.\n" if $verbose; - return "sox -n -b$bits $encoding -r$rate -c1 -traw - trim 0 $s"; + return "$SOX -n -b$bits $encoding -r$rate -c1 -traw - trim 0 $s"; } sub dialtone_subcmd { @@ -470,7 +498,7 @@ sub dialtone_subcmd { return; } 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 "; + 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" }; @@ -515,7 +543,7 @@ sub make_sox_cmd { $remix = "remix 1v0 1"; } - my $cmd = "sox -traw -b$bits $encoding -r$rate -c1 - $output $ch $remix"; + my $cmd = "$SOX -traw -b$bits $encoding -r$rate -c1 - $output $ch $remix"; my $subcmds = join(" ; ", @sox_subcmds); return "( " . $subcmds . " ) | " . $cmd; } @@ -550,6 +578,8 @@ sub check_stereo { } # main() +$SOX = $ENV{SOX} || "sox"; + for(@ARGV) { if(/--?(?:V|version)$/) { print "$SELF $VERSION\n"; @@ -563,8 +593,8 @@ for(@ARGV) { } } -if(system("sox --version > /dev/null 2>&1") != 0) { - die "$SELF: can't execute sox, is it installed?\n"; +if(system("$SOX --version > /dev/null 2>&1") != 0) { + die "$SELF: can't execute $SOX, is it installed?\n"; } if(!@ARGV) { @@ -602,7 +632,11 @@ for(@ARGV) { for ($argc = 0; $argc < @ARGV; $argc++) { $_ = $ARGV[$argc]; - if(/^--?v(?:erbose)?$/) { + if(/^--?sox$/) { + $SOX = $ARGV[++$argc]; + die "$SELF: missing argument for --sox.\n" unless defined $SOX; + warn "$SELF: sox executable set to '$SOX'\n" if $verbose; + } elsif(/^--?v(?:erbose)?$/) { $verbose = 1; } elsif(/^--?n(?:oexec)?$/) { $verbose = 1; -- cgit v1.2.3