If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Text to speech problem vb6

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Jan 2011
Posts: 1
Exclamation Text to speech problem vb6

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
Dim speech
speech = "Hello Tom"
Set ObjTextToSpeach = CreateObject("SAPI.spVoice")
ObjTextToSpeach.speak speech
Else
ObjTextToSpeech.speak "wrong password"
End If
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

can any one help ??
Reply With Quote
  #2 (permalink)  
Old
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,839
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.

i.e.:

Code:
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.
Code:
Option Explicit

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!"
      Else
         sSpeech = Replace(sSpeech, "~N-1~", CStr(N - 1))
      End If
      Me.lblStat.Caption = CStr(N - 1) & " Bottles: " & CStr(oSpeech.Speak(sSpeech))
      DoEvents
   Next N
   
   Set oSpeech = Nothing
End Sub

Private Sub cmdTalk_Click()
       
   sSpeech = Me.txtText.Text

   Me.lblStat.Caption = CStr(oSpeech.Speak(sSpeech))
   
   Set oSpeech = Nothing
   
End Sub

Private Sub Form_Load()
   ' instantiate the voice
   Set oSpeech = New SpeechLib.SpVoice
End Sub
Attached Thumbnails
Text to speech problem vb6-speechtest.png  
__________________
Lou
使大吃一惊
"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

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On