How to change volume of "say" in AppleScript? Here is a line from my AppleScript that speaks the selected text:

set this_say_Pid to do shell script "LANG=en_US.UTF-8 pbpaste -Prefer txt | say &gt; /dev/null 2&gt;&amp;1 &amp; echo $!"


I would like the speaking volume to be much lower. I would prefer not to accomplish this by decreasing my overall system volume.

I can successfully decrease the volume of say in Terminal with the following code:

say "[[volm 0.35]] This is a sentence"


But, when I insert [[volm 0.35]] in my do shell script string, the volume does not change.
Since you are piping the output of the pbpaste command directly to say command, then e.g. [[volm 0.35]] would need to be a part of what's on the clipboard as e.g. [[volm 0.35]] must precede the content of what was actually going to be said.

I'd try using the following in place of what you are using:

set howLoudAndWhatToSay to "[[volm 0.35]] \"" &amp; (get the clipboard as string) &amp; "\""

set this_say_Pid to do shell script "say " &amp; howLoudAndWhatToSay &amp; " &gt; /dev/null 2&gt;&amp;1 &amp; echo $!"




Update: If you want to stick with using pbpaste, then this example command should work:

set this_say_Pid to (do shell script "echo \"[[volm 0.35]] $(LANG=en_US.UTF-8 pbpaste -Prefer txt)\" | say &gt; /dev/null 2&gt;&amp;1 &amp; echo $!")


Note the primary differences between the command within the do shell script "..." command in your question and my answer.


echo \"[[volm 0.35]] is added in front of LANG=... and note the space after ]].
The LANG=en_US.UTF-8 pbpaste -Prefer txt is now enclosed in $(...) which is using Command Substitution to, in essence, concatenate what gets echoed to the pipe ahead of the say command.
As well as a matching closing literal double-quote \", before the pipe to say,  to go with the one in echo \"[[volm 0.35]].  It did work in limited testing without the use of the opening and closing double-quotes however it's probably better to encase it in the double-quotes to account for something the shell might try to unnecessarily expand.


That said, on my system using 0.35 for the value in [[volm 0.35]] didn't work well in that is was difficult to perceive the difference in volume from my normal setting. However using 0.3 in [[volm 0.3]] the difference was notable. (This is one of the reasons why I used "e.g. [[volm 0.35]]" in my opening sentence.)