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


ow.visible = .t.





DEFINE CLASS myevents as Custom


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

      ow = .null.

      PROCEDURE applicationevents2_startup()


      PROCEDURE applicationevents2_quit


      procedure applicationevents2_DocumentBeforeClose(Cancel,Doc)


      procedure DocumentBeforeClose(Cancel,Doc)


      procedure applicationevents2_DocumentBeforePrint(Cancel,Doc)


      procedure applicationevents2_DocumentBeforeSave(Doc,SaveAsUI,Cancel)


      procedure applicationevents2_DocumentChange


      procedure applicationevents2_DocumentOpen(Doc)


      procedure applicationevents2_NewDocument(Doc)


      procedure applicationevents2_WindowActivate(Doc,Wn)


      procedure applicationevents2_WindowBeforeDoubleClick(Sel,Cancel)


      procedure applicationevents2_WindowBeforeRightClick(Sel,Cancel)


      procedure applicationevents2_WindowDeactivate(Doc,Wn)


      procedure applicationevents2_WindowSelectionChange(Sel)


            IF sel.start < sel.end

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


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



*                sel.InsertAfter("Fox!")

*!*               mtmp = sel.text

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


      PROCEDURE destroy


            IF !ISNULL(this.ow)





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.  


  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…  


  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. Allos says:

    Hi… thanks…

    <a href=’ http://dog-training-equipment.belon.org/sled-dog-training-equipment.html ‘>sled dog training equipment</a>

    <a href=’ http://dog-training-equipment.belon.org/dog-training-equipment.html ‘>dog training equipment</a>

  17. game says:

    Nice site

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

  18. Sasha says:


    <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>

  19. home says:

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

  20. batt says:

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

  21. 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>

  22. 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>

  23. diet says:

    Nice site

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

  24. vase says:

    Great site <a href="http://pxmgywdp.tripod.com/fast-food ">fast food</a>

  25. diet says:

    Nice site

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

  26. The Best Catalog.

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

  27. thoughts from a professional developer

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

  28. gonxe says:

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

  29. aisrx says:

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

  30. edalo says:

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

Comments are closed.

Skip to main content