hey guys ive made a project which basically incorperates is a media player documents writer and over all navigation un tility all in one and i am trying to use text to speech but havin no luck i have tried this code >>
Private Sub Image2_Click()
If login.Text = "Baker" Then
speech = "Hello Tom"
Set ObjTextToSpeach = CreateObject("SAPI.spVoice")
ObjTextToSpeech.speak "wrong password"
and have had no luck it work with another program i have used which is basically just text to speech but im trying to imcorperate it with some else
As a general rule, it's good practice to explicitly declare variables. In your code below, for instance, the variable speech is declared without a data type, which means that it is a variant. In most cases, this works, but, in some cases, maybe not, or at least, not so efficiently.
Next, try explicit declaration and instantiation of the speech objects.
Dim ObjTextToSpeech as SAPI.spVoice
Set ObjTextToSpeech = new SAPI.spVoice
' when done,
set ObjTextToSpeech =nothing
Ran a quick test using MS' speech library.
Created a form with a textbox, two command buttons, a short picturebox anchored to the bottom containing a label. The controls were names (respectively) txtText, cmdTalk, cmdSing, picStat, and lblStat.
Ref the attached image, as well as the code below.
Dim sSpeech As String
Dim oSpeech As SpeechLib.SpVoice
Private Sub cmdSing_Click()
Const sLyric As String = "~N~ bottles of beer on the wall! ~N~ bottles of beer! Take 1 down, pass it around, ~N-1~ bottles of Beer on the wall..."
Dim N As Integer
For N = 99 To 1 Step -1
sSpeech = Replace(sLyric, "~N~", CStr(N))
If N = 1 Then
sSpeech = Replace(sSpeech, "~N-1~", "NO") & " And, we're all done!"
sSpeech = Replace(sSpeech, "~N-1~", CStr(N - 1))
Me.lblStat.Caption = CStr(N - 1) & " Bottles: " & CStr(oSpeech.Speak(sSpeech))
Set oSpeech = Nothing
Private Sub cmdTalk_Click()
sSpeech = Me.txtText.Text
Me.lblStat.Caption = CStr(oSpeech.Speak(sSpeech))
Set oSpeech = Nothing
Private Sub Form_Load()
' instantiate the voice
Set oSpeech = New SpeechLib.SpVoice
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert