Jump to content

Text to speak activeX script example


kjactive
 Share

Recommended Posts

I just played around on the net to look for activeX components and stumbled over an old friend of mine - TRSpeaker. This is a text to voice control, it needs some install but fair easy, the component can be used both in DHTML as in VB and all other languages that can embed objects with or witout interface ( and visual mouth )...

#include <GUIConstants.au3>

$Tx = "hi this is text to voice interface"
$oTRR = ObjCreate("TRReader.TRSpeaker.1")
$oTRH = ObjCreate("TRHelper.Helper.1")

GUICreate ( "Embedded TRSpeaker test", 640, 580,(@DesktopWidth-640)/2, (@DesktopHeight-580)/2 ,BitOr($WS_OVERLAPPEDWINDOW,$WS_VISIBLE,$WS_CLIPSIBLINGS))

$Replay = GuiCtrlCreateButton("Replay",455, 550, 60,  20)
$Interface = GuiCtrlCreateButton("Interface", 515, 550, 60, 20)
$Load = GuiCtrlCreateButton("Load",575, 550, 60,  20)
$Label = GUICtrlCreateInput($Tx,5,550,440,20)

$LinkObject = ObjEvent($oTRR,"IEEvent_","TRSpeaker"); this is a dummy events->NULL
$GUIActiveX    = GUICtrlCreateObj($oTRR, 10, 20 , 620 , 540 )

GUISetState ()      ;Show GUI

With $oTRR; Object pool
    .Speak($Tx)
EndWith

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Replay
            $tx = GUICtrlRead($Label)
            If $tx = '' Then
                MsgBox(48,"ERROR...","No text to speak available")
            Else
                $oTRR.Speak($Tx)
            EndIf
        Case $msg = $Interface
            $oTRH.ShowPage("Properties","TRReader.SpeechPropPage.1", $oTRR)
        Case $msg = $Load
            $tmp = FileLoad('Load a text file to speak out load',@DocumentsCommonDir,'Scripts (*.txt;*.au3)')
            If $tmp = '' Then 
                MsgBox(48,'ERROR...','Project Cancel')
            Else
                $ID = FileOpen($tmp,0)
                IF $ID = -1 THEN
                    MsgBox(48,'ERROR...','Project text file failed to read in')
                Else
                    $Tx = FileRead($ID,99999)
                    FileClose($ID)
                    $oTRR.Speak($Tx)
                EndIf
            EndIf
    EndSelect
WEnd
Exit

;==================================================================
;FileLoad: open a filerequester to get finename and path
;argument: display text, starting path, suffix / return the selction or empty string
;==================================================================
Func FileLoad($mess,$Path,$suff)
$var = FileOpenDialog($mess, $Path, $Suff, 5)
If @error Then Return ''
Return StringReplace($var, "|", @CRLF)
EndFunc

Download TRSpeaker:

http://www.text-reader.com/downloads/text-reader-setup-l.exe

Maybe one also need to download the 'TR Speaker component' at the same site:

http://www.text-reader.com/downloads/setup_trspeaker.exe

One also need a voice or two to load in the first time TRSpeaker starts, just use the one called mary - well just follow the install process...

If you don't have any voices installed - use Mary voice here:

http://www.text-reader.com/downloads/msttsf22l.exe

There is a lot of different free voices around this page to every languages - look it up:

http://www.text-reader.com/trspeaker_Engli...eechengines.htm

There are some control tags I did not use, feel free to change code - Have fun

This is a nice activex interface SvenP wrote...

kjactive :)

Edited by kjactive
Link to comment
Share on other sites

I don't know MS Speech that well as I don't want a 295MB download situation but TRSpeech is a very small, well designed activeX component, comes free of charges and has an intuition directly attached to control the voices peak and speed etc. and all components can be embedded and controlled in a autoit3 gui with just a few lines...

Just another ActiveX component - 'text/file to speak' thats all...

kjactive :)

Edited by kjactive
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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