我还在研究我的语音发音测试。我有这个代码,但是我需要它来使用SpeechRecognitionEngine
而不是系统弹出识别器。这段工作代码是在VB中,尽管我更喜欢在C#中工作,但这很难以解决我能得到的任何代码或编程语言。这段代码功能齐全,可以通过简单地粘贴到一个空的VB项目中来测试,包括Import System.Speech.Recognition
。有人可以告诉我如何使用SpeechEngine和。
我可以讨论设置默认音频输入并删除识别器启动代码,当然必须将其删除。但是,为了简单起见,我将代码保留为实时测试。感谢
Imports System.Speech.Recognition
Imports System.Threading
Imports System.Globalization
Public Class Form1
' recogniser & grammar
Dim recog As New SpeechRecognizer
Dim gram As Grammar
' events
Public Event SpeechRecognized As _
EventHandler(Of SpeechRecognizedEventArgs)
Public Event SpeechRecognitionRejected As _
EventHandler(Of SpeechRecognitionRejectedEventArgs)
' word list
Dim wordlist As String() = New String() {"Yes", "No", "Maybe"}
' word recognised event
Public Sub recevent(ByVal sender As System.Object,
ByVal e As RecognitionEventArgs)
LabelYes.ForeColor = Color.LightGray
LabelNo.ForeColor = Color.LightGray
LabelMaybe.ForeColor = Color.LightGray
If (e.Result.Text = "Yes") Then
LabelYes.ForeColor = Color.Green
ElseIf (e.Result.Text = "No") Then
LabelNo.ForeColor = Color.Green
ElseIf (e.Result.Text = "Maybe") Then
LabelMaybe.ForeColor = Color.Green
End If
End Sub
' recognition failed event
Public Sub recfailevent(ByVal sender As System.Object,
ByVal e As RecognitionEventArgs)
LabelYes.ForeColor = Color.LightGray
LabelNo.ForeColor = Color.LightGray
LabelMaybe.ForeColor = Color.LightGray
End Sub
' form initialisation
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
' need these to get British English rather than default US
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB")
Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-GB")
' convert the word list into a grammar
Dim words As New Choices(wordlist)
gram = New Grammar(New GrammarBuilder(words))
recog.LoadGrammar(gram)
' add handlers for the recognition events
AddHandler recog.SpeechRecognized, AddressOf Me.recevent
AddHandler recog.SpeechRecognitionRejected, AddressOf Me.recfailevent
' enable the recogniser
recog.Enabled = True
End Sub
End Class