Click here to Skip to main content
Rate this: bad
good
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 but...how 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
            IO.File.Delete("C:\Test\grammar.xml")
        End If
        choices.Add("red")
        builder.Append(choices)
        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")
        doc.WriteSrgs(writer)
        writer.Close()
        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
        sw.Start()
        Do While sw.ElapsedMilliseconds < interval
            Application.DoEvents()
        Loop
        sw.Stop()
    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.SetInputToDefaultAudioDevice()
 
        engine.RecognizeAsync() 'that's my fail to recognize...
        wait(3000)
        engine.RecognizeAsyncStop()
    End Sub
 
End Class
Infinite thanks for anyone who can help me!
Posted 2-Jul-12 8:39am
Edited 2-Jul-12 8:42am
v5
Comments
Sergey Alexandrovich Kryukov at 3-Jul-12 0:33am
   
Please don't re-post; use "Improve question" and the page or you original question.
--SA

1 solution

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

Solution 1

WTF | :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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2014
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