プログラムで作成した文法を読み込もうとすると、エラーが発生しました: SAPI は音声アルファベットの選択を実装していません。
私のコード:
Public Class Form1
Dim engine As New Speech.Recognition.SpeechRecognitionEngine
Dim gram As new Speech.Recognition.Grammar("C:\Test\Speech\mygrammar.xml")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim choices = New Recognition.Choices()
choices.Add("Red")
choices.Add("Blue")
choices.Add("Green")
choices.Add("Yellow")
Dim gb = New GrammarBuilder()
gb.Append(choices)
Dim doc = New Speech.Recognition.SrgsGrammar.SrgsDocument(gb)
IO.Directory.CreateDirectory("C:\Test")
IO.Directory.CreateDirectory("C:\Test\Speech")
Dim xWriter = System.Xml.XmlWriter.Create("C:\Test\Speech\mygrammar.xml")
doc.WriteSrgs(xWriter)
xWriter.Close()
Dim compiledFile = New FileStream("C:\Test\Speech\mycompiledgrammar.cfg", FileMode.OpenOrCreate)
Speech.Recognition.SrgsGrammar.SrgsGrammarCompiler.Compile("C:\Test\Speech\mygrammar.xml", compiledFile)
compiledFile.Close()
サブ終了
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
engine.LoadGrammar(gram) 'There's the error
engine.SetInputToWaveFile("D:\record.wav")
End Sub
End Class