Is there a way to use the MS Speech utility from command line? I can do it on a mac, but can't find any reference to it on Windows XP.
-
Relevant: https://askubuntu.com/questions/53896/natural-sounding-text-to-speech – 0 _ Aug 17 '17 at 02:27
-
Relevant: https://askubuntu.com/questions/21811/how-can-i-install-and-use-text-to-speech-software – 0 _ Aug 17 '17 at 02:27
7 Answers
My 2 cents on the topic, command line one-liners:
on Win using
PowerShell.exe
PowerShell -Command "Add-Type –AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('hello');"
on Win using
mshta.exe
mshta vbscript:Execute("CreateObject(""SAPI.SpVoice"").Speak(""Hello"")(window.close)")
on OSX using
say
say "hello"
Ubuntu Desktop (>=2015) using native
spd-say
spd-say "hello"
on any other Linux
- refer to How to text-to-speech output using command-line?
- commandline function using google TTS (wget to mp3->mplayer)
- command using google with mplayer directly:
/usr/bin/mplayer -ao alsa -really-quiet -noconsolecontrols "http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&q=Hello%20World&tl=en"
;
on Raspberry Pi, Win, OSX (or any remote) using Node-Red

- 3,221
- 35
- 38
-
2
-
1
-
1@ColorCodin sounds like, you need to run it in an elevated environment. Like running "cmd.exe as Administrator" or granting access to mshta.exe for all users. – BananaAcid Jul 10 '18 at 21:19
-
-
@MacMarde you would search stackoverflow for "vbscript change audio input" or something similiar – BananaAcid Jan 15 '22 at 23:35
-
I can verify that the liners for OSX and Win-PS work for me. When I attempted with Win-CMD, no audio was generated. - Why is it? – Azhar Sep 29 '22 at 01:44
-
@Azhar since `mshta.exe` is a very old way of calling scripts, might be security restrictions on Win10/Win11 - pwershell is the modern way to go. – BananaAcid Sep 30 '22 at 11:52
There's a nice open source program that does what you're asking for on Windows called Peter's Text to Speech available here: http://jampal.sourceforge.net/ptts.html
It contains a binary called ptts.exe that will speak text from standard input, so you can run it like this:
echo hello there | ptts.exe
Alternatively, you could use the following three line VBS script to get similar basic TTS:
'say.vbs
set s = CreateObject("SAPI.SpVoice")
s.Speak Wscript.Arguments(0), 3
s.WaitUntilDone(1000)
And you could invoke that from the command line like this:
cscript say.vbs "hello there"
If you go the script route, you'll probably want to find some more extensive code examples with a variable timeout and error handling.
Hope it helps.

- 6,502
- 5
- 32
- 35
-
You can install Peter's Text to Speech program, [Jampal](http://sourceforge.net/projects/jampal/files/jampal/) and then execute the ptts.vbs file to play text files. The voices you choose need to be installed already in Windows. Example: `C:\Program Files\Jampal>cscript "c:\program files\jampal\ptts.vbs" -voice "IVONA Amy" < raven.txt` and `C:\Program Files\Jampal>cscript "c:\program files\jampal\ptts.vbs" -voice "IVONA Jennifer" < raven.txt` – Anonymous User Jul 14 '13 at 01:41
There's also Balabolka: http://www.cross-plus-a.com/bconsole.htm
It has a command line tool balcon.exe
. You can use it like this:
List voices:
balcon.exe -l
Speak file:
balcon.exe -n "IVONA 2 Jennifer" -f file.txt
Speak from the command-line:
balcon.exe -n "IVONA 2 Jennifer" -t "hello there"
More command line options are available. I tried it on Ubuntu with SAPI5 installed in Wine. It works just fine.

- 8,726
- 2
- 49
- 47

- 51
- 1
- 1
-
Balabolka is cool. It does the job and nothing else, you can configure the hell out of the voice. And it's alive, I just downloaded the new version. So yes, this is an upvote situation. – dkellner Sep 28 '22 at 07:49
If you can't find a command you can always wrap the System.Speech.Synthesis.SpeechSynthesizer from .Net 3.0 (Don't forget to reference "System.Speech")
using System.Speech.Synthesis;
namespace Talk
{
class Program
{
static void Main(string[] args)
{
using (var ss = new SpeechSynthesizer())
foreach (var toSay in args)
ss.Speak(toSay);
}
}
}

- 1,107
- 9
- 32

- 22,160
- 4
- 52
- 69
-
using github.com/oleg-shilo/cs-script this can be used from commandline without compiling and without visual studio – BananaAcid Mar 11 '19 at 18:52
There is a powershell way also:
Create a file called speak.ps1
param([string]$inputText)
Add-Type –AssemblyName System.Speech
$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer
$synth.Speak($inputText);
Then you can call it
.\speak.ps1 "I'm sorry Dave, I'm afraid I can't do that"

- 5,932
- 3
- 45
- 72
rem The user decides what to convert here
:input
cls
echo Type in what you want the computer to say and then press the enter key.
echo.
set /p text=
rem Making the temp file
:num
set num=%random%
if exist temp%num%.vbs goto num
echo ' > "temp%num%.vbs"
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "temp%num%.vbs"
echo speech.speak "%text%" >> "temp%num%.vbs"
start temp%num%.vbs
pause
del temp%num%.vbs
goto input
pause

- 31
- 1
Your best approach is to write a small command line utility that will do it for you. It would not be a lot of work - just read text in and then use the ms tts library.
Another alternative is to use Cepstral. It comes with a nice command line utility and sounds light years better than the ms tts.

- 7,518
- 3
- 26
- 33