Bonjour,

J'ai un code vba que j'aimerais optimiser pour alimenter une listbox à partir de ce que je dit au micro.

Voici mon code actuel :
-----------------------------------------------------------------------------------------------------------------------------------------
Option Explicit

Private WithEvents ListeningSession As SpSharedRecoContext

Private Grammar As ISpeechRecoGrammar



Private Sub CommandButton1_Click()
'store results in top left cell of current sheet

Range("A1").Value = Me.TextBox1.Text

'speak them aloud to confirm

Application.Speech.Speak ("You said " & Me.TextBox1.Text)

End Sub

Private Sub UserForm_Initialize()

If (ListeningSession Is Nothing) Then

Set ListeningSession = New SpSharedRecoContext

Set Grammar = ListeningSession.CreateGrammar(1)

Grammar.DictationLoad

End If

Grammar.DictationSetState (SpeechRuleState.SGDSActive)

End Sub



Private Sub CommandButton2_Click()

'store results in top left cell of current sheet

Range("A1").Value = Me.TextBox1.Text

'speak them aloud to confirm

Application.Speech.Speak ("You said " & Me.TextBox1.Text)

End Sub

Private Sub ListeningSession_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal result As SpeechLib.ISpeechRecoResult)

'store this in the textbox on your form on a new line

Me.TextBox1.Value = Me.TextBox1.Value & vbNewLine & result.PhraseInfo.GetText
------------------------------------------------------------------------------------------------------------------------------------------

Ce code peut rapidement être mis en place en créant u userform avec seulement une listbox et un bouton commande.

Le code fonctionne en l'état mais quand je le lance entre ce que je dit et ce qu'il est marqué dans la listbox y'a une sacré différence. J'aimerais savoir si il est possible de l'optimiser (peut-êttre en s'aidant d'une bibliothéque (dll) ou autre.

J'ai un code sur python qui fonctionne très bien avec speech_recognition et j'aimerais me rapprocher du resultat mais avec du VBA.

Merci par avance de votre aide