Creating the chat bot 3 - The speech Addon

Post date: Oct 26, 2014 12:18:06 PM

Speech is an important part of communication, the microsoft speech API offers all we need to consume.

Lets Use it!

The speech add on : here we add Microsoft speech to our project.

Imports System.Speech.Recognition

Imports System.Speech.Synthesis

'Speech synthasis methods

'------------------------------------------------------------------------------------------------------------------------------------------------------

''' <summary>

''' enables voice recognition engine

''' </summary>

''' <remarks></remarks>

Public WithEvents RecoEngine As New SpeechRecognitionEngine()

''' <summary>

''' Enable TexttoSpeech

''' </summary>

''' <remarks></remarks>

Private SpeechSynth As New SpeechSynthesizer

''' <summary>

''' Sets up Speech Recognition for use

''' </summary>

''' <remarks></remarks>

Public Sub SetupRecognition()

RecoEngine.LoadGrammar(New DictationGrammar())

RecoEngine.SetInputToDefaultAudioDevice()

RecoEngine.RecognizeAsync()

End Sub

''' <summary>

''' Activated on completion of recognition

''' </summary>

''' <param name="sender"></param>

''' <param name="e"></param>

''' <remarks></remarks>

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

RecoEngine.RecognizeAsync()

End Sub

''' <summary>

''' On recogonizing speech the input is sent to the response routine

''' </summary>

''' <param name="sender"></param>

''' <param name="e"></param>

''' <remarks></remarks>

Private Sub RecoEngine_SpeechRecognized(ByVal sender As Object, ByVal e As System.Speech.Recognition.RecognitionEventArgs) Handles RecoEngine.SpeechRecognized

'a call to act is requird here

ProcessInputText(e.Result.Text)

End Sub

''' <summary>

''' Speaktext Uses the internal speech system to speak the text, using the SAPI

''' </summary>

''' <param name="NewText">String: Text to be spoken</param>

''' <remarks></remarks>

Public Sub SpeakText(ByRef NewText As String)

SpeechSynth.Speak(NewText)

End Sub

The source files have been created using Microsoft visual studio 2013.

feel free to use and change as well as distribute!