Results 1 to 2 of 2
  1. #1
    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 ??

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,844
    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 Attached Thumbnails 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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •