2017-08-25 5 views
1

Kürzlich habe ich versucht, einen Chatbot für die Schule zu erstellen, und eines der Features, die ich wollte, war die Spracherkennung. Leider gibt es aufgrund der veralteten Version von VB6 sehr wenige Tutorials zur Verwendung von SAPI für die Spracherkennung mit VB6 und überhaupt keine zum Freigeben von Diktion (einfaches Sprechen ohne Grammatik und Konvertieren von Sprache in Text).So aktivieren Sie freie Rede Spracherkennung in VB6 mit SAPI

+0

Sie verwenden Microsoft Speech API (SAPI) 5.4, die Teil von Microsoft Windows SDK für Windows 7 ist? –

+0

@PedroPolonia Ja –

Antwort

1

Automation Interfaces and Objects (SAPI 5.4) hat die Dokumentation.

triviales Beispiel:

Option Explicit 

'See "Automation Interfaces and Objects (SAPI 5.4)" at MSDN. 

Private WithEvents RC As SpeechLib.SpInProcRecoContext 
Private RG As SpeechLib.ISpeechRecoGrammar 

Private Sub Form_Load() 
    With New SpeechLib.SpInprocRecognizer 
     Set RC = .CreateRecoContext() 
     Set .AudioInput = .GetAudioInputs().Item(0) 
    End With 
    With RC 
     .EventInterests = SRERecognition Or SREFalseRecognition 
     Set RG = .CreateGrammar() 
    End With 
    RG.DictationSetState SGDSActive 
End Sub 

Private Sub Form_Resize() 
    If WindowState <> vbMinimized Then 
     Text1.Move 0, 0, ScaleWidth, ScaleHeight 
    End If 
End Sub 

Private Sub Form_Unload(Cancel As Integer) 
    RG.DictationSetState SGDSInactive 
End Sub 

Private Sub RC_FalseRecognition(_ 
    ByVal StreamNumber As Long, _ 
    ByVal StreamPosition As Variant, _ 
    ByVal Result As SpeechLib.ISpeechRecoResult) 

    With Text1 
     .SelStart = &H7FFF 
     .SelText = "False Rec: " 
     .SelText = Result.PhraseInfo.GetText() 
     .SelText = vbNewLine 
    End With 
End Sub 

Private Sub RC_Recognition(_ 
    ByVal StreamNumber As Long, _ 
    ByVal StreamPosition As Variant, _ 
    ByVal RecognitionType As SpeechLib.SpeechRecognitionType, _ 
    ByVal Result As SpeechLib.ISpeechRecoResult) 

    With Text1 
     .SelStart = &H7FFF 
     .SelText = "Rec: " 
     .SelText = Result.PhraseInfo.GetText() 
     .SelText = vbNewLine 
    End With 
End Sub