Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speech Recognition in SQL Database VB.net

I have an SQL Database application and I want to incorporate a voice search feature. I already know how to search the database but I don't know how I can make a grammar from the table in my database. Here's my code so far.

Dim WithEvents reco As New Recognition.SpeechRecognitionEngine


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

    reco.SetInputToDefaultAudioDevice()

    Dim gram As New Recognition.SrgsGrammar.SrgsDocument

    Dim RecipeRule As New Recognition.SrgsGrammar.SrgsRule("recipe")

    Dim colorsList As New Recognition.SrgsGrammar.SrgsOneOf(DataSet1.Table.ToString)

    RecipeRule.Add(colorsList)

    gram.Rules.Add(RecipeRule)

    gram.Root = RecipeRule

    reco.LoadGrammar(New Recognition.Grammar(gram))

    reco.RecognizeAsync()

End Sub

Private Sub reco_RecognizeCompleted(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognizeCompletedEventArgs) Handles reco.RecognizeCompleted

    reco.RecognizeAsync()

End Sub

Private Sub reco_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles reco.SpeechRecognized
    Try
        Me.TableTableAdapter.Recipe(Me.DataSet1.Table, e.Result.Text & "%")
    Catch ex As System.Exception
        System.Windows.Forms.MessageBox.Show(ex.Message)
    End Try
End Sub

I need to make the items in the recipe row in DataSet1.Table the grammar.

like image 410
kaanay03 Avatar asked Jan 27 '17 23:01

kaanay03


1 Answers

SrgsOneOf has a constructor which takes a string[] as parameter: https://msdn.microsoft.com/en-us/library/ms554280(v=vs.110).aspx

Your current code tries to convert the table to a string, which isn't going to work. Instead, you could create an array of strings by iterating the table.

It's not clear from the post whether the table contains individual words/phrases as rows, or a singleton row with a list of words/phrases.

Assuming each row has a word or phrase

Example:

DataTable
---------
red
green
blue
indigo

There are multiple ways to do this (creating an ArrayList, using LINQ) but here's a very basic method:

Dim rowCount As Integer = DataSet1.Table.Rows.Count
Dim arrWords(rowCount) As String 
For i = 0 to rowCount - 1 
  arrWords(i)=DataSet1.Table.Rows(i)(0).ToString();
Next

Dim colorsList As New Recognition.SrgsGrammar.SrgsOneOf(arrWords)

Assuming there is one row containing all the words/phrases

In this case, I'm going to assume that they are comma-delimited.

Example:

DataTable
---------
red,green,blue,indigo

In this case, just use Split to create an array:

Dim strWords as String = DataSet1.Table.Rows(i)(0).ToString()
Dim arrwords As String() = strWords.Split(New Char() {","c})

Dim colorsList As New Recognition.SrgsGrammar.SrgsOneOf(arrWords)
like image 150
meisen99 Avatar answered Oct 21 '22 06:10

meisen99