语音识别无法正常工作

时间:2018-01-29 00:16:11

标签: vb.net

你能帮帮我吗?启动时,下面的代码有一个陌生人的警告/错误。我得到一条消息,如#34;没有安装识别器"。我该怎么办?我已经将它作为x86 CPU运行了。

Option Strict On

Imports System.Speech
Imports System.Speech.Recognition
Imports System.Speech.Recognition.SrgsGrammar

Public Class Form1

Dim WithEvents reco As New SpeechRecognitionEngine
Dim synth As New Synthesis.SpeechSynthesizer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Try

        Dim gram As New SrgsDocument
        Dim colorRule As New SrgsRule("color")
        Dim colorsList As New SrgsOneOf("red", "green")

        colorRule.Add(colorsList)
        gram.Rules.Add(colorRule)
        gram.Root = colorRule
        reco.LoadGrammarAsync(New Recognition.Grammar(gram))
        reco.SetInputToDefaultAudioDevice()
        reco.RecognizeAsync(RecognizeMode.Multiple)

    Catch s As Exception
        MessageBox.Show(s.Message)
    End Try


End Sub

Private Sub reco_SpeechDetected(ByVal sender As Object, ByVal e As System.Speech.Recognition.SpeechDetectedEventArgs) Handles reco.SpeechDetected
    Label1.Text = "Voz detectada"
End Sub

Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized
    Select Case e.Result.Text
        Case "vermelho"
            SetColor(Color.Red)
        Case "verde"
            SetColor(Color.Lime)
    End Select
End Sub


Private Sub SetColor(ByVal color As System.Drawing.Color)
    reco.RecognizeAsyncCancel()
    reco.RecognizeAsyncStop()
    synth.Speak("mudando cor para " & color.ToString)
    Me.BackColor = color
    reco.RecognizeAsync(RecognizeMode.Multiple)
End Sub
End Class

P.S。:我用葡萄牙语运行Windows 7,有什么问题吗?

0 个答案:

没有答案