Click here to Skip to main content
12,945,933 members (63,527 online)
Rate this:
Please Sign up or sign in to vote.
When I try to load the grammar for the speech recognition I got this error:
SAPI does not implement phonetic alphabet selection. I use the default speech DLL for the recognition.

And...I know it's a noob question to recognize my voice automatically and then put the text into a textbox?

My code:
Imports System.Speech
Imports System.Xml
Imports System.IO
Public Class Form1
    Dim choices As New Speech.Recognition.Choices
    Dim builder As New Speech.Recognition.GrammarBuilder
    Dim engine As New Speech.Recognition.SpeechRecognitionEngine
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If IO.File.Exists("C:\Test\grammar.xml") Then
        End If
        Speech.Recognition.GrammarBuilder.Add(choices, builder)
        Dim doc As New Speech.Recognition.SrgsGrammar.SrgsDocument(builder)
        Dim writer As Xml.XmlWriter = XmlWriter.Create("C:\Test\grammar.xml")
        AddHandler engine.LoadGrammarCompleted, AddressOf Me.HandleSpeechRecognized
    End Sub
    Public Sub HandleSpeechRecognized(ByVal sender As Object, _
           ByVal e As System.EventArgs)
        MsgBox("Grammar loaded") 'I just use it to see if the grammar is loaded...big fail
    End Sub
    Private Sub wait(ByVal interval As Integer)
        Dim sw As New Stopwatch
        Do While sw.ElapsedMilliseconds < interval
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim grammar As New Speech.Recognition.Grammar("C:\Test\grammar.xml")
        engine.LoadGrammar(grammar) 'there's the error
        engine.RecognizeAsync() 'that's my fail to recognize...
    End Sub
End Class

Infinite thanks for anyone who can help me!
Posted 2-Jul-12 7:39am
Updated 2-Jul-12 7:42am
Please don't re-post; use "Improve question" and the page or you original question.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

:WTF: You wired up the LoadGrammarCompleted event (which you don't need and wiredup to the WRONG handler BTW), but not the SpeechRecognized event?? How are you going to get notified that the engine heard something??

When you finally get the event handler written and wired up, you can get the Text of the recognition Result out of the event args you are passed in the handler.

AddHandler engine.SpeechRecognized, AddressOf SpeechRecognizedHandler

You can delete the other AddHandler line and put the above in it's place. You're not calling LoadGrammarAsync so the LoadGrammarCompleted event won't do you any good.

Then you can easily get the text of the recognized speech...
Private Sub SpeechRecognizedHandler(ByVal sender As Object, ByVal e As SpeechRecognizedEventArgs)
        Console.WriteLine("Recognized: " & e.Result.Text)
    End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,205
Maciej Los 2,453
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100