Pages

Tuesday, August 24, 2010

Enabling Text-to-Speech in MS Word 2007

One of my friend told me if she want to have a text-to-speech application to assist her in teaching,
then i advised her to use one of ms office feature about speech recognition, which i knew in ms office 2003, but she had been using office 2007 for her purposes.

i tried to find in ms office 2007 feature, is this text-to-speech (TTS) exist or not, like as in office 2003... And i didn't find that.

Does ms office remove all TTS feature from office 2007 or there is something to do to enable it?

After googling to find this case, apparently, it needs some trick to make TTS active :
  1. when ms word 2007 is active, press alt+F11 (hold the Alt key down then press the F11 key) to open VBA Code editor

  2. in VBA Code Editor, select on 'Normal', see on picture.



  3. then insert new module by left click > insert > module, as shown on picture.



  4. add this code into new module:
  5. Option Explicit
    Dim speech As SpVoice
    Dim i As Integer

    Sub SpeakText()
    On Error Resume Next
    If i = 0 Then
    Set speech = New SpVoice
    If Len(Selection.Text) > 1 Then 'speak selection
    speech.Speak Selection.Text, SVSFlagsAsync + SVSFPurgeBeforeSpeak
    Else 'speak whole document
    speech.Speak ActiveDocument.Range(0, ActiveDocument.Characters.Count).Text, SVSFlagsAsync + SVSFPurgeBeforeSpeak
    End If
    Else
    If i = 1 Then
    speech.Resume
    i = 0
    End If
    End If

    End Sub

    Sub Stopspeaking()
    On Error Resume Next
    speech.Speak vbNullString
    Set speech = Nothing
    i = 0

    End Sub

    Sub Pausespeaking()
    On Error Resume Next
    If i = 0 Then
    speech.Pause
    i = 1
    Else
    If i = 1 Then
    speech.Resume
    End If
    End If

    End Sub


  6. enable speech library by Select the Tools > References... menu option. Scan the list of references and click the little box next the Speech library, then click OK, see on pict



  7. save this module then return to ms word (File > Close and return to microsoft word).

  8. In order to conveniently run your macros, you will probably want to add three buttons to the quick access tool bar. You can do this by clicking the small downward arrow with the "Customize quick access toolbar" tooltip on the title bar of MS Word near the Save, Undo and Redo buttons. Select "More commands" in the dropdown menu to open the "Word options" window. Select "Customize" on left hand menu and "Choose commands from" should be set to "Macros". Add all three macros and this will create three buttons on the quick access tool bar. You can modify the button icons to more closely represent the TTS functions.

  9. Now your MS word is TTS enabled. Just click the Start, Pause, or Stop button

No comments:

Post a Comment