Results 1 to 5 of 5

Thread: Pause disbaled

  1. #1

    Thread Starter
    Registered User
    Join Date
    Feb 2015
    Posts
    3

    Pause disbaled

    Hello

    I have been trying to make a simple text to speech program. However, I cannot get the pause button to work along with everything else when the text to speech works. the computer reads and disables all buttons from being pressed, is
    this because I have the choose voice option on? By the way, I am new to the forums and visual basic.

    Code:
    Iports System.Speech.Synthesis
    Imports System.IO
    Imports SpeechLib
    
    Public Class Form1
        Dim speech As New SpeechSynthesizer
        Dim oVoice As New SpeechLib.SpVoice
        Private V As SpeechLib.SpVoice
        Private T As SpeechLib.ISpeechObjectToken
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim oVoice As New SpeechLib.SpVoice
            Dim cpFileStream As New SpeechLib.SpFileStream
    
            oVoice.Voice = oVoice.GetVoices.Item(cmbVoices.SelectedIndex)
            oVoice.Speak(TextBox1.Text,
                SpeechLib.SpeechVoiceSpeakFlags.SVSFDefault)
            oVoice = Nothing
            Button2.Enabled = True
            Me.Cursor.Handle.ToInt64()
    
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            oVoice.Pause()
        End Sub
    
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            oVoice.Resume()
        End Sub
    
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
            oVoice.SpeakAsyncCancelAll()
        End Sub
    
        Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
            Dim sfd As New SaveFileDialog
            sfd.Filter = "Mp3|*.mp3|Wav|*.wav"
            sfd.Title = "Save To Audio Files"
            sfd.RestoreDirectory = True
            If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim fs As New FileStream(sfd.FileName, FileMode.Create, FileAccess.Write)
                oVoice.SetOutputToWaveStream(fs)
                oVoice.Speak(Me.TextBox1.Text)
                fs.Close()
                MsgBox("Saved!")
            End If
        End Sub
    
        Private Sub Form1_load(sender As Object, e As EventArgs) Handles Me.Load
            '    Dim x As New SpeechLib.SpVoice
            '   Dim arrVoices As SpeechLib.ISpeechObjectTokens = x.GetVoices
            '  Dim arrLst As New ArrayList
            ' For i As Integer = 0 To arrVoices.Count - 1
            'arrLst.Add(arrVoices.Item(i).GetDescription)
            ' Next
            'cmbVoices.DataSource = arrLst
            cmbVoices.Visible = False
        End Sub
    
        Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
            cmbVoices.Visible = True
            Dim x As New SpeechLib.SpVoice
            Dim arrVoices As SpeechLib.ISpeechObjectTokens = x.GetVoices
            Dim arrLst As New ArrayList
            For i As Integer = 0 To arrVoices.Count - 1
                arrLst.Add(arrVoices.Item(i).GetDescription)
            Next
            cmbVoices.DataSource = arrLst
        End Sub
    End Class
    Thank You

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,238

    Re: Pause disbaled

    There is an issue in the Button1_Click method. You have created variable oVoice at form scope. Inside that method, though, you create a new variable called oVoice, which will hide the form level variable as far as that method is concerned. You then use that local oVoice variable within the method and destroy it. That should work well enough within the button, but you should be aware that the oVoice that you are using in the button click is not the same variable as the oVoice variable you reference anywhere else in the code. That's almost certainly wrong. I believe that you don't want to be creating a new instance in the button click method, and that you certainly don't want to be destroying it, either.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Registered User
    Join Date
    Feb 2015
    Posts
    3

    Re: Pause disbaled

    Thank You Shaggy Hiker. However, I am new to vb and didn't quite understand what I should now. I was searching for how to get the voice list which is why button1 has that code. Could you please tell me the code on how to fix the issue? Once again, thank you!

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,238

    Re: Pause disbaled

    I'm not the one to answer that. If the code in button1 is just test code, then the fact that a second instance of the object in a variable that masked the form level variable, probably isn't the issue. However, I haven't worked with the library any, so I'm not even quite sure what you expect it to do.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    Registered User
    Join Date
    Feb 2015
    Posts
    3

    Re: Pause disbaled

    I expect that when the user clicks on button1 they are able to have the text in texbox1 read to them after they have selected a voice by clicking the voice button. I would then like the user to be able to pause the text to speech by clicking pause, which is disabled along with everything else when the speech is on I hope that explains it a bit more and thank you for your help. Oh, by the way, if I take away the code for button1 and replace it with speech.speak(texbox1.text) everything is enabled and works as should.

Posting Permissions

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



Click Here to Expand Forum to Full Width