Jump to content

Command line text-to-speech program?


kahlil88

Recommended Posts


You can use VBScript or AutoIt 3 to access the SAPI object.

Here is a AutoIt example that can be compiled to say.exe and use a CLI switch to run it i.e. say.exe "this is a test parameter". The VBScript syntax is similar to translate to.


If $CMDLINE[0] = 1 Then
; call function using cli parameter
_Say($CMDLINE[1], 1, 100)
Else
; else call function with a warning
_Say('No parameters used')
EndIf

Func _Say($sText, $iRate = 1, $iVolume = 100)
; use sapi text to speech
If $iRate > 10 Or $iVolume > 100 Then Return
Local $oTalk = ObjCreate('SAPI.SpVoice')
If Not @error Then
With $oTalk
.Rate = $iRate
.Volume = $iVolume
.Speak($sText, 1)
.WaitUntilDone(500)
.Pause()
Sleep(1000)
.Resume()
.WaitUntilDone(-1)
EndWith
EndIf
EndFunc

:)

Link to comment
Share on other sites

The Wikipedia articles are a bit skimpy. Can I run these from the command line the same way I run say? I mostly want to use it for goofing around (i.e. making my computer tell mom jokes or praising GNU/Linux operating systems :P).

Link to comment
Share on other sites

You can use VBScript or AutoIt 3 to access the SAPI object.

Here is a AutoIt example that can be compiled to say.exe and use a CLI switch to run it i.e. say.exe "this is a test parameter". The VBScript syntax is similar to translate to.


If $CMDLINE[0] = 1 Then
; call function using cli parameter
_Say($CMDLINE[1], 1, 100)
Else
; else call function with a warning
_Say('No parameters used')
EndIf

Func _Say($sText, $iRate = 1, $iVolume = 100)
; use sapi text to speech
If $iRate > 10 Or $iVolume > 100 Then Return
Local $oTalk = ObjCreate('SAPI.SpVoice')
If Not @error Then
With $oTalk
.Rate = $iRate
.Volume = $iVolume
.Speak($sText, 1)
.WaitUntilDone(500)
.Pause()
Sleep(1000)
.Resume()
.WaitUntilDone(-1)
EndWith
EndIf
EndFunc

:)

I had previously used the Text to Speech UDF available on Autoit forums in a QC application. It does work but were some bugs iirc.

Link to comment
Share on other sites

  • 2 weeks later...
I had previously used the Text to Speech UDF available on Autoit forums in a QC application. It does work but were some bugs iirc.

Sorry for late reply. I would like to comment that using XP 32 bit I had no problems at all with scripting SAPI with AutoIt or VBScript. Under Vista 32 Bit is little joy as the sound drivers that I have are not good in certain sound generation methods used. I use the Creative card and drivers that are not quite there yet for the card that i have. Perhaps some similar issues is your recognition of disappointment with using scripts to using SAPI?

Link to comment
Share on other sites

I had previously used the Text to Speech UDF available on Autoit forums in a QC application. It does work but were some bugs iirc.

Sorry for late reply. I would like to comment that using XP 32 bit I had no problems at all with scripting SAPI with AutoIt or VBScript. Under Vista 32 Bit is little joy as the sound drivers that I have are not good in certain sound generation methods used. I use the Creative card and drivers that are not quite there yet for the card that i have. Perhaps some similar issues is your recognition of disappointment with using scripts to using SAPI?

For me, the UDF by itself was not a good enough problem. I eventually disabled that feature of my program because it had certain memory leaks. For example, sometimes it would play sound, sometimes it would lock up the computer or the sound would skip. It was because my program did not give the ability to stop playing the audio, so there was no control of it. Another thing, you couldn't close my program until the sound stopped playing, or end process caused instability or sound wouldn't work anymore until a reboot.

I do not have the source code handy that I used, it has been archived to DVD a while ago.

Link to comment
Share on other sites

  • 5 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...