Speech Command in VB

  • Thread starter Thread starter Curtis Stevens
  • Start date Start date
C

Curtis Stevens

I am using this code to use the speech feature in Access. You type a name in
the box, click the button and it speaks it for you. However, it doesn't work
in 2007 like it did in 2002. I made sure the reference in VB to the speech
one is still in tact.

Any idea what needs to be updated? The error I get is Run-time error
-2147200967. Method Item of Object ISpeechObjectTokens failed. And points
to this line of code: Set mobjVoice.Voice = mobjVoice.GetVoices().Item(2)

=============
' This code was originally written by
' Doug Steele, MVP (e-mail address removed)
'
' You are free to use it in any application
' provided the copyright notice is left unchanged.
'
' Note that the commented code represents what the previous line of
' code would be if you're using Late Binding.
' For instance, below you'll see
' Dim mobjVoice As SpeechLib.SpVoice
' 'Dim mobjVoice As Object
'
' If you want to use Late Binding, you can comment out the first line
' and uncomment the second line, rather than what's presented here.

Dim mobjVoice As SpeechLib.SpVoice
'Dim mobjVoice As Object

=================

Private Sub cmdSpeak_Click()
Dim strText As String

' Provide a phrase to speak if the user didn't.
strText = Me.Contact & vbNullString
If Len(strText) = 0 Then
strText = "Nada"
End If

' Instantiate the Voice object, if necessary
If mobjVoice Is Nothing Then
Set mobjVoice = New SpeechLib.SpVoice
' Set mobjVoice = CreateObject("SAPI.SpVoice")
End If

' Set the Voice, Rate and Volume to use
Set mobjVoice.Voice = mobjVoice.GetVoices().Item(2)
mobjVoice.Rate = -4
mobjVoice.Volume = 50

' Speak the phrase
mobjVoice.Speak strText, SVSFlagsAsync Or SVSFPurgeBeforeSpeak
' mobjVoice.Speak strText, 1 Or 2

End_cmdSpeak_Click:
Exit Sub
 
Back
Top