无法在system.speech中加载语法(以及有关识别的信息) [英] Cannot load grammar in system.speech (and about recognition)

查看:154
本文介绍了无法在system.speech中加载语法(以及有关识别的信息)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试为语音识别加载语法时,出现此错误:
SAPI不实现语音字母选择.我使用默认的语音DLL进行识别.

而且...我知道这是一个菜鸟问题,但是...如何自动识别我的声音,然后将文本放入文本框?

我的代码:

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


对能帮助我的人表示无限感谢!

推荐答案

:WTF:您已将LoadGrammarCompleted事件连接起来(不需要这样做)和有线连接到WRONG处理程序BTW),但不是SpeechRecognized事件?您将如何收到有关引擎听到的声音的通知?

最终编写并连接事件处理程序后,可以从在处理程序中传递的事件args中获取识别结果的文本.

: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


您可以删除另一行AddHandler并将其放在上面.您不会调用LoadGrammarAsync,因此LoadGrammarCompleted事件不会对您有任何帮助.

然后,您可以轻松获取已识别语音的文本...


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


这篇关于无法在system.speech中加载语法(以及有关识别的信息)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆