Word to audible speech

Here’s some interesting code to run. It starts Microsoft Word and binds some Fox code to some Word events.

Type some text into the document. Select some text.

When the Selection Change event occurs, the Foxpro code creates the speech API object and speaks out loud the currently selected text.

ow = CREATEOBJECTex("word.application","","")

omyevents = CREATEOBJECT('myevents')

omyevents.ow = ow

?EVENTHANDLER(ow,omyevents)

ow.visible = .t.

ow.Activate

ow.Documents.Add

*ow.Quit

DEFINE CLASS myevents as Custom

      oSapi=0

      implements applicationevents2 IN "C:\Program Files\Microsoft Office\OFFICE11\msword.olb"

      ow = .null.

      PROCEDURE applicationevents2_startup()

            ?PROGRAM()

      PROCEDURE applicationevents2_quit

            ?PROGRAM()

      procedure applicationevents2_DocumentBeforeClose(Cancel,Doc)

            ?PROGRAM()

      procedure DocumentBeforeClose(Cancel,Doc)

            ?PROGRAM()

      procedure applicationevents2_DocumentBeforePrint(Cancel,Doc)

            ?PROGRAM()

      procedure applicationevents2_DocumentBeforeSave(Doc,SaveAsUI,Cancel)

            ?PROGRAM()

      procedure applicationevents2_DocumentChange

            ?PROGRAM()

      procedure applicationevents2_DocumentOpen(Doc)

            ?PROGRAM()

      procedure applicationevents2_NewDocument(Doc)

            ?PROGRAM()

      procedure applicationevents2_WindowActivate(Doc,Wn)

            ?PROGRAM()

      procedure applicationevents2_WindowBeforeDoubleClick(Sel,Cancel)

            ?PROGRAM()

      procedure applicationevents2_WindowBeforeRightClick(Sel,Cancel)

            ?PROGRAM()

      procedure applicationevents2_WindowDeactivate(Doc,Wn)

            ?PROGRAM()

      procedure applicationevents2_WindowSelectionChange(Sel)

            ?PROGRAM(),sel.text

            IF sel.start < sel.end

                  IF VARTYPE(this.oSapi)!='O'

                        this.oSapi=CREATEOBJECT("SAPI.spVoice.1")

* this.oSapi.Voice=this.oSapi.GetVoices().Item(1)

                  ENDIF

                  this.oSapi.Speak(sel.text)

* sel.InsertAfter("Fox!")

*!* mtmp = sel.text

*!* sel.text=STRTRAN(mtmp,"good","Great!")

            endif

      PROCEDURE destroy

  ?PROGRAM()

            IF !ISNULL(this.ow)

                  ?EVENTHANDLER(this.ow,this,.t.)

            ENDIF

ENDDEFINE