Speech recognition, problème détection de mot dynamique

Signaler
Messages postés
26
Date d'inscription
jeudi 26 février 2009
Statut
Membre
Dernière intervention
28 février 2016
-
Bonjour, je souhaite votre aide pour une fonction.
j'ai fait un petit programme en vb.net pour reconnaître ma voix , je sais reconnaître des mot stocker dans grammar dans le but de contrôler des commande relay domotique pour allumer ou éteindre les lumières , tv et autre par control vocale.

ca fonctionne trep bien , mais j'en veux plus.
interactivité en fonction de ce que je lui donne comme commande vocale.

ex: si je prend une textbox et que j'ecrit "bonjour je suis andré" je peux placer ceci dans une variable "name" et ne garder que "andré" pour pouvoir réutiliser plus bas pour qu'une textbox2 ecrive "bonjour(name) comment va tu ?"

je voudrai faire ceci avec la reconnaissance vocale.

parler et stocker ce que j'ai dit dans une variable puis travailler avec, et pas avec une liste de mot préenregistré dans le grammar.

voici un exemple de mon code avec la reconnaissance "musique" pour lancer une playlist.

Imports System.Speech
Imports System.Speech.Synthesis
Public Class Form1
Dim WithEvents reco As New Recognition.SpeechRecognitionEngine 'ControlVocale
Dim alecoute As Boolean
Dim TextALireBack As String
Dim TextALirePro As String
Dim synth As New Synthesis.SpeechSynthesizer



Public Sub Control()
reco.SetInputToDefaultAudioDevice()
Dim gram As New Recognition.SrgsGrammar.SrgsDocument
Dim CommandRule As New Recognition.SrgsGrammar.SrgsRule("Commande")
Dim CommandList As New Recognition.SrgsGrammar.SrgsOneOf("musique")
CommandRule.Add(CommandList)
gram.Rules.Add(CommandRule)
gram.Root = CommandRule
reco.LoadGrammar(New Recognition.Grammar(gram))
reco.RecognizeAsync()
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 "iris"
If alecoute = True Then GoTo dejaecoute
alecoute = True
If Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Normal
Me.Location = New Point((My.Computer.Screen.WorkingArea.Width / 2) - (Me.Width / 2), (My.Computer.Screen.WorkingArea.Height / 2) - (Me.Height / 2))
Me.ShowInTaskbar = True
ElseIf Me.WindowState = FormWindowState.Normal Then
Me.TopMost = True
Me.TopMost = False
End If
Me.BackgroundImage = My.Resources.IRISVert
Me.Icon = My.Resources.IRISVertIcon
Timer1.Start()
dejaecoute:
Case "musique"
TextALireBack = "voila!"
TextALirePro = "C:\Users\Atelier\Desktop\avi.m3u"
BackgroundWorkerTextProcess.RunWorkerAsync()
End Select
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 Setcmd(ByVal txt As String)
synth.Speak(txt)
Me.BackgroundImage = My.Resources.IRISRouge
Me.Icon = My.Resources.IRISRougeIcon
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If BackgroundWorkerText.IsBusy = True Then
Timer1.Stop()
alecoute = False
Else
Timer1.Stop()
alecoute = False
Me.BackgroundImage = My.Resources.IRISRouge
Me.Icon = My.Resources.IRISRougeIcon
End If
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
CheckForIllegalCrossThreadCalls = False
Me.BackgroundImage = My.Resources.IRISRouge
Me.Icon = My.Resources.IRISRougeIcon
Control()
End Sub
Public Sub IRISText(ByVal TextALire As String)
If alecoute = True Then
alecoute = False
Setcmd(TextALire)
End If
End Sub
Public Sub IRISProcess(ByVal ProcessAExecuter As String)
If alecoute = True Then
alecoute = False
Process.Start(ProcessAExecuter)
End If
End Sub
Public Sub IRISTextEtProcess(ByVal TextALire As String, ByVal ProcessAExecuter As String)
If alecoute = True Then
alecoute = False
Setcmd(TextALire)
Process.Start(ProcessAExecuter)
End If
End Sub
Public Sub IRISArretProcess(ByVal ProcessAArreter As String)
If alecoute = True Then
alecoute = False
Dim myProcesses As Process() = Process.GetProcessesByName(ProcessAArreter)
Dim myProcess As Process
For Each myProcess In myProcesses
myProcess.Kill()
Next myProcess
alecoute = False
End If
End Sub
Dim drag As Boolean
Dim mousex As Integer
Dim mousey As Integer
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
drag = True
mousex = Windows.Forms.Cursor.Position.X - Me.Left
mousey = Windows.Forms.Cursor.Position.Y - Me.Top
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If drag Then
Me.Top = Windows.Forms.Cursor.Position.Y - mousey
Me.Left = Windows.Forms.Cursor.Position.X - mousex
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
drag = False
End Sub

Private Sub Form1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDoubleClick
Me.WindowState = FormWindowState.Minimized
End Sub

Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorkerText.DoWork
If alecoute = True Then
Me.BackgroundImage = My.Resources.IRISBleu
Me.Icon = My.Resources.IRISBleuIcon
IRISText(TextALireBack)
End If

End Sub

Private Sub BackgroundWorker2_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorkerTextProcess.DoWork
If alecoute = True Then
Me.BackgroundImage = My.Resources.IRISBleu
Me.Icon = My.Resources.IRISBleuIcon
IRISTextEtProcess(TextALireBack, TextALirePro)
End If

End Sub

Private Sub BackgroundWorkerArreterPro_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorkerArreterPro.DoWork
If alecoute = True Then
Me.BackgroundImage = My.Resources.IRISBleu
Me.Icon = My.Resources.IRISBleuIcon
IRISArretProcess(TextALirePro)
End If

End Sub

Private Sub BackgroundWorkerArreterPro_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorkerArreterPro.RunWorkerCompleted
Me.TopMost = True
Me.TopMost = False
End Sub
End Class