none
Detect Sapi End RRS feed

  • Question

  • Hi all,

    I want control the SAPI output with a timer.

    If Sapi is completed wi want start a spoken information.

    I tried this with a code like
     

    If SAPI.Completed = true then

    'Do something

    End if
    Whitout success. Can someone explain the funtion to me pleas?


    Liebe Grüße Stefan

    Wednesday, September 11, 2019 2:26 PM

Answers

  • Hi,

    Note that you need to add a reference to Microsoft Speech object library in the COM option.

    You can try my code as follows:

    Imports SpeechLib
    Imports System.Runtime.InteropServices
    Public Class Form1
        Dim SAPI As SpVoice = New SpVoice
        Dim lngHandle As Long
        Dim lngRtn As Long
    
        <DllImport("kernel32.dll")>
        Private Shared Function WaitForSingleObject(ByVal hHandle As IntPtr, ByVal dwMilliseconds As Integer) As Long
        End Function
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Try
                SAPI.Volume = 100
                SAPI.Rate = 5
                SAPI.Speak(TextBox1.Text, SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync)
                lngHandle = SAPI.SpeakCompleteEvent
                lngRtn = WaitForSingleObject(lngHandle, 200)
                Dim t As New Timer With {.Interval = 100, .Enabled = True}
                AddHandler t.Tick, Sub()
                                       If SAPI.Status.RunningState = 1 Then
                                           t.Stop()
                                           MsgBox("111")
                                       End If
                                   End Sub
            Catch ex As Exception
            End Try
        End Sub
    End Class

    Hope I can help you.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sirius32ds Thursday, September 12, 2019 12:21 PM
    Thursday, September 12, 2019 9:57 AM
    Moderator

All replies

  • Hi,

    Note that you need to add a reference to Microsoft Speech object library in the COM option.

    You can try my code as follows:

    Imports SpeechLib
    Imports System.Runtime.InteropServices
    Public Class Form1
        Dim SAPI As SpVoice = New SpVoice
        Dim lngHandle As Long
        Dim lngRtn As Long
    
        <DllImport("kernel32.dll")>
        Private Shared Function WaitForSingleObject(ByVal hHandle As IntPtr, ByVal dwMilliseconds As Integer) As Long
        End Function
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Try
                SAPI.Volume = 100
                SAPI.Rate = 5
                SAPI.Speak(TextBox1.Text, SpeechLib.SpeechVoiceSpeakFlags.SVSFlagsAsync)
                lngHandle = SAPI.SpeakCompleteEvent
                lngRtn = WaitForSingleObject(lngHandle, 200)
                Dim t As New Timer With {.Interval = 100, .Enabled = True}
                AddHandler t.Tick, Sub()
                                       If SAPI.Status.RunningState = 1 Then
                                           t.Stop()
                                           MsgBox("111")
                                       End If
                                   End Sub
            Catch ex As Exception
            End Try
        End Sub
    End Class

    Hope I can help you.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sirius32ds Thursday, September 12, 2019 12:21 PM
    Thursday, September 12, 2019 9:57 AM
    Moderator
  • Hi,

    If you have anything else about this issue, please feel free to contact us.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 16, 2019 7:06 AM
    Moderator