Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

playing sound in a TCL script

79 views
Skip to first unread message

Cecil Westerhof

unread,
Dec 16, 2017, 1:59:06 PM12/16/17
to
At the moment I have a Bash script in which I use:
play --no-show-progress -n synth .25 vol .1

to give a notification sound.

I am thinking about rewriting the script into a TCL script. The
command I use is an external command, but I was wondering if I could
make the script OS independent. But until now I did not find
something. Is there a way to do this, or not?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Robert Heller

unread,
Dec 16, 2017, 2:43:12 PM12/16/17
to
At Sat, 16 Dec 2017 19:54:09 +0100 Cecil Westerhof <Ce...@decebal.nl> wrote:

>
> At the moment I have a Bash script in which I use:
> play --no-show-progress -n synth .25 vol .1
>
> to give a notification sound.
>
> I am thinking about rewriting the script into a TCL script. The
> command I use is an external command, but I was wondering if I could
> make the script OS independent. But until now I did not find
> something. Is there a way to do this, or not?

There isn't "built in" support for sound. You have to use exec and run an
external program:

exec play --no-show-progress -n synth .25 vol .1

And may have to wrap it with a test (eg if or switch) using the ::tcl_platform
array.

>

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services

Christian Gollwitzer

unread,
Dec 16, 2017, 3:27:33 PM12/16/17
to
Am 16.12.17 um 20:43 schrieb Robert Heller:
> At Sat, 16 Dec 2017 19:54:09 +0100 Cecil Westerhof <Ce...@decebal.nl> wrote:
>
>>
>> At the moment I have a Bash script in which I use:
>> play --no-show-progress -n synth .25 vol .1
>>
>> to give a notification sound.
>
> There isn't "built in" support for sound. You have to use exec and run an
> external program:

Not built-in, but there is a package called snack: https://wiki.tcl.tk/2647
Last time I checked, it had certain signs of bitrot - not keeping up
with the changes in the Linux sound system - you'll have to check
yourself. If you only want to play a short notification sound, it might
still be easier to exec an external program for that. Snack can give
much more control (mixing several sounds, changing loudness, generating
sounds etc.)

Christian

Cecil Westerhof

unread,
Dec 16, 2017, 3:28:04 PM12/16/17
to
Robert Heller <hel...@deepsoft.com> writes:

> At Sat, 16 Dec 2017 19:54:09 +0100 Cecil Westerhof <Ce...@decebal.nl> wrote:
>
>>
>> At the moment I have a Bash script in which I use:
>> play --no-show-progress -n synth .25 vol .1
>>
>> to give a notification sound.
>>
>> I am thinking about rewriting the script into a TCL script. The
>> command I use is an external command, but I was wondering if I could
>> make the script OS independent. But until now I did not find
>> something. Is there a way to do this, or not?
>
> There isn't "built in" support for sound. You have to use exec and run an
> external program:
>
> exec play --no-show-progress -n synth .25 vol .1

I was afraid of that, but it never hurts to verify.


> And may have to wrap it with a test (eg if or switch) using the ::tcl_platform
> array.

Why are you using ::tcl_platform instead of ${tcl_platform}?

Robert Heller

unread,
Dec 16, 2017, 3:50:48 PM12/16/17
to
The double colon means the global namespace. Since tcl_platform is an array
is not meaningful to reference it as a scalar. You need to reference it with
a array "index" (key), something like this:

switch $::tcl_platform(os) {
Linux {
exec play --no-show-progress -n synth .25 vol .1
}
Windows {
}
Darwin {

Cecil Westerhof

unread,
Dec 16, 2017, 4:44:07 PM12/16/17
to
That makes my live easier. Somewhere else I use:
global tcl_platform
.
.
.
$tcl_platform(user)

But in this way I can drop the global. Learning all the time. Thanks.

Brad Lanam

unread,
Dec 17, 2017, 2:02:33 PM12/17/17
to
On Saturday, December 16, 2017 at 10:59:06 AM UTC-8, Cecil Westerhof wrote:
> At the moment I have a Bash script in which I use:
> play --no-show-progress -n synth .25 vol .1
>
> to give a notification sound.
>
> I am thinking about rewriting the script into a TCL script. The
> command I use is an external command, but I was wondering if I could
> make the script OS independent. But until now I did not find
> something. Is there a way to do this, or not?

The SoX toolkit is available for Windows also.
I cannot seem to get it to play though.
Maybe you will have better luck.

(copy sox.exe to play.exe)

C:\Program Files (x86)\sox-14-4-2>play.exe --no-show-progress -n synth .25 vol .1
play.exe FAIL sox: Sorry, there is no default audio device configured

Some people say that using version 14.4.1 works for them.


I have a VLC interface written:
http://wiki.tcl.tk/48382
This would be much heavier resource usage
and you would have to pre-generate your sound files.
More complicated to use, but certainly cross platform.

sled...@gmail.com

unread,
Dec 18, 2017, 1:14:21 PM12/18/17
to
There are two (other) methods that may be used with Windows. I have used both.
1. snack,
2. MS SAPI

I will leave it to your imagination to consider which is the easiest to implement.

Rick
0 new messages