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


 

Comments (54)

  1. Great sample Calvin.

    Note that this uses MS-Word 11 (Office 2003). For previous versions you’d have to adjust accordingly. For example, at work I use Office 2000 (Office9) so the path there would be:

    implements applicationevents2 IN "C:Program FilesMicrosoft OfficeOFFICEmsword9.olb"

  2. Ken Weber says:

    Can this be done without hardcoding a path to the OLB?

  3. Thierry says:

    implements applicationevents2 IN "Word.Application"

  4. George says:

    Hi, Extremely neat! is there an equivalent SAPI .DLL for W2K O-S’s?

  5. Payday Loan says:

    Very nice and informative website.

  6. Katrina says:

    Very nice website with a lot of informative response from members

  7. buy xanax says:

    i like your website very much but please do get us more information about it

  8. The EventHandler function allows you to connect some code to an object’s event interface. For example,…

  9. used-car says:

    Nice job…

    <a href="http://used-car-dealer-dallas.u4fgf.info "> used car dealer dallas</a>

  10. Britney says:

    Hi, nice very nice page..!

    <a href=’http://www.blogpostworld.org/blog-code-music-site-web.html‘>blog code music site web</a>

    <a href=’http://www.blogpostworld.org/blog-from-music.html‘>blog from music</a>

    <a href=’http://www.blogpostworld.org/blog-music-music.html‘>blog music music</a>

  11. None says:

    Hello, Nice site. I am able to learn many stotras. Very good work.  

    http://company-christmas-party.orhat.info

  12. Bill says:

    When all else fails, read the instructions

    <a href=’http://cingular-prepaid-wireless.rjnrh3.info/billing-cingular-wireless.html‘>billing cingular wireless</a>

  13. used-car says:

    Nice job…

    <a href="http://used-car-dealer-dallas.u4fgf.info "> used car dealer dallas</a>

  14. None says:

    Hello, This site is simply very good…  

    http://sapasor.orgfree.com/

  15. Max says:

    Hi… thanks…

    <a href=’ http://coffee-maker.belon.org/bunn-coffee-maker-repair-part.html ‘>bunn coffee maker repair part</a>

    <a href=’ http://coffee-maker.belon.org/bunn-coffee-maker-recall.html ‘>bunn coffee maker recall</a>

  16. game says:

    Nice site

    <a href=’ http://shurl.net/2nz ‘> game </a>

  17. Sasha says:

    thanks…

    <a href=’ http://ford-truck.fw3gd.info/1949-ford-truck.html ‘>1949 ford truck</a>

    <a href=’ http://ford-truck.fw3gd.info/san-antonio-ford-truck.html ‘>san antonio ford truck</a>

  18. home says:

    nice  <a href=’ http://homebusiness.belon.org ‘> home business </a>

  19. batt says:

    nice site <a href= http://battery-laptop.d3ald.info > battery laptop </a>

  20. CtOIHik says:

    nice site

    <a href= http://pills.belon.org/claritin-and-blood-pressure >claritin and blood pressure</a>

    <a href= http://kasta.belon.org/allergy-medication-singular >allergy medication singular</a>

  21. fpOikos says:

    No, no, no

    <a href= http://pills.belon.org/com-singular >com singular</a>

    <a href= http://pills.belon.org/claritin-kid >claritin kid</a>

  22. diet says:

    Nice site

    <a href="http://tradewits.org/dog-food-natural ">dog food natural</a>

  23. diet says:

    Nice site

    <a href=" http://zr2d4nmn.tripod.com/buy-online-wii "> buy online wii</a>

  24. The Best Catalog.

    <a href=http://healthpiece.info/>Real”>http://healthpiece.info/>Real Catalog</a>[url=http://healthpiece.info/]The Real Catalog[/url]

  25. thoughts from a professional developer

    I do not agree. Go to http://apartments.waw.pl/

  26. gonxe says:

    <a href=" http://school-ut3.0catch.com/ ">Bible high school literature</a>

  27. aisrx says:

    <a href=" http://school-ut3.0catch.com/ ">Bible high school literature</a>

  28. edalo says:

    I like this site! <a href=" http://free-8-a2.0catch.com/ ">Free graphic organizers</a> wokrg

Skip to main content