How to get around “say” command bug when setting volume?

Solution 1:

The best is to put '[[volm 0.35]] ' into the shell (not in the clipboard), like this:

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

Or, if you want to put "[[volm 0.35]] " into the clipboard, use the single quotes, like this:

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

Solution 2:

Simply add a comma after the [[volm 0.35]] part of your shell script. A space after the comma is probably not required.

set the clipboard to ("[[volm 0.35]], " & ("\n- This is a test."))

This also eliminates the second error (hyphen and text without separating space).