# vb.net microsoft voice platform help



## shuggans (May 3, 2013)

writing an auto dication application using the microsoft voice platform 11 (Speech SDK): have a few questions on it.  the application has a start and stop button which should start and stop the voice engine from listening.  

Question 1: when I click the start button, the microsoft speech recognition UI pops up alongside the application - is there a way to keep this from happening and completely control the speech functionality through MY application?  

Question 2: the start and stop buttons do not start and stop anything despite these line of code:

```
Grammar.DictationSetState(SpeechRuleState.SGDSActive)
```
and:

```
Grammar.DictationSetState(SpeechRuleState.SGDSInactive)
```

You still have to use the speech engine UI to start and stop listening, any idea on how to actually call it to start listenning through a vb.net button?

Full code is here:

```
Imports System
Imports System.Data
Imports System.Deployment
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Xml
Imports System.Speech
Imports SpeechLib

Public Class Form1
    Dim WithEvents RecoContext As SpSharedRecoContext
    Dim Grammar As ISpeechRecoGrammar
    Dim CharCount As Integer
    Dim var_TextInsetion As Boolean = True
    Dim var_ReadBack As Boolean = False

    Private Sub Button_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Start.Click
        If (RecoContext Is Nothing) Then
            RecoContext = New SpSharedRecoContext
            Grammar = RecoContext.CreateGrammar(1)
            Grammar.DictationLoad()
        End If
        Grammar.DictationSetState(SpeechRuleState.SGDSActive)
        Button_Start.Enabled = False
        Button_Stop.Enabled = True

    End Sub

    Private Sub Button_Stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Stop.Click

        Grammar.DictationSetState(SpeechRuleState.SGDSInactive) 'Turns off the Recognition. It will go dormant.

        Button_Start.Enabled = True
        Button_Stop.Enabled = False
    End Sub

    Private Sub OnHypo(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal Result As ISpeechRecoResult) Handles RecoContext.Hypothesis
        Button_Stop.Enabled = False
        Label_Phrase.Text = "Dictating..."
    End Sub



    Private Sub OnReco(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechRecognitionType, ByVal Result As ISpeechRecoResult) Handles RecoContext.Recognition
        'create text string from recognized speech
        Dim recoResult As String = Result.PhraseInfo.GetText
        Label_Phrase.Text = recoResult & " "
        CharCount = CharCount + 1 + Len(recoResult)
        If var_TextInsetion = True Then
            SendKeys.Send(recoResult & " ")
        End If
        Button_Stop.Enabled = True
        If var_ReadBack = True Then
            If recoResult = "Backspace" Or recoResult.StartsWith("Select") Then
            Else
                Dim synth
                synth = CreateObject("SAPI.spvoice")
                synth.Speak(recoResult)
            End If
        End If
    End Sub


    Private Sub CheckBox_TextInsertion_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox_TextInsertion.CheckedChanged
        If CheckBox_TextInsertion.CheckState = CheckState.Checked Then
            var_TextInsetion = True
        Else
            var_TextInsetion = False
        End If
    End Sub

    Private Sub CheckBox_ReadBack_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox_ReadBack.CheckedChanged
        If CheckBox_ReadBack.CheckState = CheckState.Checked Then
            var_ReadBack = True
        Else
            var_ReadBack = False
        End If
    End Sub
End Class
```


----------



## shuggans (May 6, 2013)

Any ideas?  Or does anyone know anywhere I could ask that is familiar with this SDK?


----------



## Mindweaver (May 6, 2013)

I've not used the Speech SDK. I would be interested to see some screen shots of the Speech engine UI popup. So, if I understand what you are saying.. You created a button that calls the Speech engine UI popup event? You should be able to do something like take the start button on the speech engine UI and (I don't know what it's called this is just an example) _*bt_start.performclick*_ inside your button *click event*.


----------

