Search code examples
vb.netsapi

Error in programming


Imports SpeechLib

Public Class Form1
    Public vox = CreateObject("sapi.spvoice")
    Private Sub cmdSpeak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSpeak.Click
        Dim t As String = "Hello , This is a Text"
        Say(t)
    End Sub

    Public Sub Say(ByVal text As String)
        vox.Speak(text,SpeechVoiceSpeakFlags.SVSFlagsAsync)
    End Sub

    Private Sub cmdPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPause.Click
        vox.pause()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        vox.AlertBoundary = SVEPhoneme
    End Sub
End Class

I am getting an error

Name 'SVEPhoneme' is not declared.

How and where do I declare it ?


Solution

  • It is SpeechVoiceEvents.SVEPhoneme

    This is all a lot easier if you make this code early bound:

    Public vox as New SpVoice
    

    Or better yet, use the .NET wrapper for the sapi, System.Speech assembly.

    Imports System.Speech.Synthesis
    
    Public Class Form1
        Public vox As New SpeechSynthesizer
    
        Public Sub Say(ByVal text As String)
            vox.SpeakAsync(text)
        End Sub
    End Class