Results 1 to 2 of 2
Thread: Text to speech problem vb6
01-17-11, 10:59 #1Registered User
- Join Date
- Jan 2011
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
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
can any one help ??
01-19-11, 19:06 #2Super Moderator
- Join Date
- Jun 2004
- Arizona, USA
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
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.
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