'** HeadBot - Copied from DRHead and Box Head from long ago '** Just the basic frame but should work for the most part '** V1.00 - Stephen W Nolen / Protowrxs 2015 '** May not need all these - they have been added over time Imports System.Speech.Recognition Imports System.Speech.Synthesis Imports System.Collections.ObjectModel Imports System.Net.WebClient Imports System.Threading Imports System.Globalization Imports System Imports System.IO.Ports Imports System.Net Imports System.Xml '** Load up the main form and take off '** There are a few variables you may want to adjust '** Public Class Form1 Dim UsingWin7 As Boolean = True '** I'm sure this can be figured out in code BUT for now... Dim RobotName As String = "Robot" '** Give your bot a simple but unique name for best results Dim YourName As String = "My Great Creator" '** What you want your HeadBot to call you when you wake him up Dim MyComPortIndex As Integer = 0 '** Change this to the pull down index (0-??) for your default port Dim HeadBotBirthDay As Date = "10/31/2015" '** Set to the date your bot was "born" Dim WaitForSpeech As Boolean = True '** ONLY needed for MS voices if you are animated a jaw or mouth, otherwise leave as false Dim myComPort As New SerialPort '** Com port for communications Dim GetComResponse As Boolean = False '** IF you want to get/display responses from Arduino then TRUE '** If TRUE and nothing there you get delays waiting for data Dim InBoundData As String '** From MCU Dim myspeaker As New SpeechSynthesizer '** Speech synth output Dim ListenFlag As Boolean '** This determines if he listens for everything or just Hello 'Robotname' Dim webClient = New System.Net.WebClient() '** Used for getting data from / to the web Dim Mytext As String '** General text holder Dim LastContactTime As Date '** Last time he heard / did something for future mood swings Dim StartTime As Date '** When wer started up for general "I've been up since" stuff Dim CurrentHeard As String '** text from recognizer to use Dim PreviousHeard As String '** previous text from last heard for trying to repeat things that didn't work Dim AnimateJaw As Boolean = True '** starts out ON but you can change by saying please use your slack jaw Dim eSpeak As Boolean = False '** COMMENT out to use MS voice Dim SpeechPitch As Integer = 50 '** This is for the eSpeech engine only Dim SpeechPitchNormal As Integer = SpeechPitch Dim OldSpeechPitch As Integer Dim SpeechSpeed As Integer = 175 Dim SpeechSpeedNormal As Integer = SpeechSpeed Dim OldSpeechSpeed As Integer Dim MSSpeechSpeed As Integer = 1 '** This is for the MS Speech engines and only used if eSpeak if FALSE Dim MSSpeechSpeedNormal As Integer = MSSpeechSpeed '** Saving this form "Normal" speech return '** Setup recogniser & grammar Dim recog2 As New SpeechRecognizer Dim recog As New SpeechRecognitionEngine Dim gram As Grammar '** Setup the events handler for recognition Public Event SpeechRecognized As EventHandler(Of SpeechRecognizedEventArgs) Public Event SpeechRecognitionRejected As EventHandler(Of SpeechRecognitionRejectedEventArgs) '** word list - This the list of words/phrases we are recognizing. '** We would like to move this to a file so we can add things on the fly like names, etc Dim wordlist As String() = New String() {RobotName, "Hello " & RobotName, "Goodbye " & RobotName, "How are you doing", _ "Please Look to the Left", "please look to the right", "Please Look Forward", _ "Please Look Middle", "Please look up", "Please look down", _ "Whats the latest news", "What is your name", "Who are you", _ "What time is it", "Thats incorrect", "its ok " & RobotName, _ "Are you happy", "Whats your age", "How old are you", _ "How many days until Christmas", "How many days until halloween", _ "Whats new at cool kids robots", _ "You look handsome", "That didn't work", "Thank you " & RobotName & "", _ "Please speak lower", "Please speak higher", "Please speak normal", _ "Please speak faster", "Please speak slower", _ "Please animate your jaw", "Please use your slack jaw", _ "Please give me a wink", "Please use e speak voice", "Please use micro soft voice", _ "Please use your blue eyes", "Please use your red eyes", "Please use your green eyes", _ "Please use your red mouth", "Please use your green mouth", "Please use your blue mouth"} '** Word recognised event Public Sub recevent(ByVal sender As System.Object, ByVal e As RecognitionEventArgs) '** If we recongized a word/phrase then turn off recog so we don't hear ourself 'recog.Enabled = False '** If using WinXP use this recog.RecognizeAsyncCancel() '** If using Win7/8/etc use this If (e.Result.Text = "Hello " & RobotName) Then '** This is the wake up call that turns on the listen flag SendCommand("F") '** Start out looking forward SendCommand("H") '** This is the basic "head wobble" command to the MCU SayIt(RandomInterjection("PREFIX") & ", Hello " & YourName & "!") '** and say Hi ListenFlag = True End If If ListenFlag Then '** If we are in LISTEN MODE then we process '** If we are listening and heard something we understand then we start processing CurrentHeard = e.Result.Text '** save the new heard value PreviousHeard = lblVoiceStatus.Text '** save the previous heard in case we need to repeat '** If the command wasn't done you can use that didn't work to have him/her repeat the last command '** we just load up the CurrentHeard with the previous heard phrase for processing '** Problem is it saves this off as that didn't work multiple times doesn't work.. oh the irony... If e.Result.Text = "That didn't work" Then SayIt(RandomInterjection("PREFIX") & ", let me try it again then.") CurrentHeard = PreviousHeard TextHeard.Text = CurrentHeard & vbCrLf & TextHeard.Text End If lblVoiceStatus.Text = CurrentHeard '** Update the form label so we know what was said TextHeard.Text = CurrentHeard & vbCrLf & TextHeard.Text '** Handle the results commands here If (CurrentHeard = RobotName) Then SendCommand("H") SayIt("Yes?") ElseIf (CurrentHeard = "Please use e speak voice") Then eSpeak = True SayIt(RandomInterjection("PREFIX") & ", I should now be using e speak voice") ElseIf (CurrentHeard = "Please use micro soft voice") Then eSpeak = False SayIt(RandomInterjection("PREFIX") & ", I should now be using my micro soft voice") ElseIf (CurrentHeard = "What is your name") Or (CurrentHeard = "Who are you") Then SendCommand("H") SayIt("My name is " & RobotName & ", but you can call me " & RobotName & ".") ElseIf (CurrentHeard = "Please give me a wink") Then If CInt(Math.Ceiling(Rnd() * 100)) > 50 Then SendCommand("W") SayIt("Hey there sexy thang.") Else SendCommand("w") SayIt("Well, I Hope I did that correctly.") End If ElseIf (CurrentHeard = "Thank you " & RobotName) Then SendCommand("H") SayIt("You're welcome") ElseIf (CurrentHeard) = "Your welcome" Or (CurrentHeard = "Your right") Then SendCommand("H") SayIt("Thank you") ElseIf (CurrentHeard = "Please animate your jaw") Then SendCommand("H") AnimateJaw = True SayIt(RandomInterjection("POSITIVE") & ". My jaw should now animate when speaking.") ElseIf (CurrentHeard = "Please use your slack jaw") Then SendCommand("H") AnimateJaw = False SayIt(RandomInterjection("PREFIX") & ". My jaw is no longer animated. Feels better to my servo even.") ElseIf (CurrentHeard = "Please Look Up") Then '** If your bot CAN look up then change this SayIt("Ok") SendCommand("U") ElseIf (CurrentHeard = "please look to the right") Then SendCommand("R") SayIt("Ok") ElseIf (CurrentHeard = "Please Look Down") Then '** If your bot CAN look down then change this SayIt("Ok") SendCommand("D") ElseIf (CurrentHeard = "Please Look to the Left") Then SendCommand("L") SayIt("Ok") ElseIf (CurrentHeard = "Please Look Forward") Then SendCommand("F") SayIt("Ok") ElseIf (CurrentHeard = "Please Look Middle") Then SendCommand("M") SayIt("Ok") ElseIf (CurrentHeard = "Please look up") Then SendCommand("U") SayIt("OK") ElseIf (CurrentHeard = "Please look down") Then SendCommand("D") SayIt("OK") ElseIf (CurrentHeard = "Please speak higher") Then SendCommand("H") SayIt("Ok") SpeechPitch = SpeechPitch + 25 If SpeechPitch > 200 Then SpeechPitch = 200 SayIt(RandomInterjection("POSITIVE") & ", I am now speaking a little higher.") If SpeechPitch >= 100 Then SayIt("Seriously, this feels really ackward talking like this.") End If ElseIf (CurrentHeard = "Please speak lower") Then SendCommand("H") SayIt("Ok") SpeechPitch = SpeechPitch - 10 If SpeechPitch < 1 Then SpeechPitch = 1 SayIt("I am now speaking a little lower.") ElseIf (CurrentHeard = "Please speak faster") Then SendCommand("H") SayIt("OK") If eSpeak Then SpeechSpeed = SpeechSpeed + 25 Else MSSpeechSpeed = MSSpeechSpeed + 1 myspeaker.Rate = MSSpeechSpeed End If SayIt("I am now speaking a little faster.") If (SpeechSpeed > 250) Or (MSSpeechSpeed > 5) Then SayIt("Gee, I do not see how you understand what I am saying this fast.") End If ElseIf (CurrentHeard = "Please speak slower") Then SendCommand("H") SayIt("OK") If eSpeak Then SpeechSpeed = SpeechSpeed - 25 Else MSSpeechSpeed = MSSpeechSpeed - 1 myspeaker.Rate = MSSpeechSpeed End If SayIt(RandomInterjection("POSITIVE") & ", I am now speaking a little slower") If (SpeechSpeed < 100) Or (MSSpeechSpeed < -5) Then SayIt("Wow, you must be really dumb to need me to speak this slow at rate " & MSSpeechSpeed) End If ElseIf (CurrentHeard = "Please speak normal") Then SendCommand("H") SayIt("Ok") If eSpeak Then SpeechPitch = SpeechPitchNormal SpeechSpeed = SpeechSpeedNormal Else MSSpeechSpeed = MSSpeechSpeedNormal myspeaker.Rate = MSSpeechSpeed End If SayIt("Ahh, good, I am now speaking my normal voice.") ElseIf (CurrentHeard = "Tell me the weather forecast") Or (CurrentHeard = "How is the weather") Then SendCommand("H") SayIt(RandomInterjection("WAIT")) SayWeather() ElseIf CurrentHeard = "Whats new at cool kids robots" Or CurrentHeard = "Whats new at C K R" Then SendCommand("H") SayIt("Just a second, getting cool stuff") ReadRss("http://www.coolkidsrobots.com/rss.xml") ElseIf (CurrentHeard = "Whats the latest news") Then SendCommand("H") SayIt(RandomInterjection("WAIT")) 'ReadRSS("http://news.yahoo.com/rss/") ReadRss("http://news.yahoo.com/rss/us") ElseIf (CurrentHeard = "How are you doing") Then SendCommand("H") SayIt(RandomInterjection("POSITIVE") & "I'm doing fine, just stuck here on my stand.") SayIt("It has been " & DateDiff("s", LastContactTime, Now()) & " seconds since someone talked to me") SayIt("I've been active for " & DateDiff("s", StartTime, Now()) & " seconds as well.") ElseIf (CurrentHeard = "What time is it") Then SendCommand("H") SayIt("Looks like the current time is " & TimeOfDay() & " to me.") ElseIf (CurrentHeard = "What is the date") Then SendCommand("H") SayIt("Looks like the current date is " & DateString & " to me.") ElseIf (CurrentHeard = "Thats incorrect") Or (CurrentHeard = "Thats pretty bad") Or (CurrentHeard = "Thats not funny") Then SendCommand("D") SayIt("Sorry about that...") ElseIf (CurrentHeard = "its ok " & RobotName) Or (CurrentHeard = "Good job") Or (CurrentHeard = "That is correct") Or (CurrentHeard = "That worked") Then SendCommand("H") SayIt("Good, thank you.") ElseIf (CurrentHeard = "Are you happy") Then SendCommand("H") SayIt("Usually I am, but sometimes I get bored just sitting here.") ElseIf (CurrentHeard = "Whats your age") Or (CurrentHeard = "How old are you") Then SendCommand("H") SayIt(RandomInterjection("PREFIX") & ", I was created around " & HeadBotBirthDay & " so I guess I am about " & DateDiff("d", HeadBotBirthDay, Now()) & " days old.") ElseIf (CurrentHeard = "How many days until Christmas") Then SendCommand("H") SayIt(RandomInterjection("WAIT") & ".") SayDateDiff("Christmas") ElseIf (CurrentHeard = "How many days until halloween") Then SendCommand("H") SayIt("Cool, that is my favorite holiday!") SayDateDiff("Halloween") ElseIf (CurrentHeard = "Please use your red eyes") Then SendCommand("r") SayIt(RandomInterjection("PREFIX") & ", My eyes should now be red!") ElseIf (CurrentHeard = "Please use your blue eyes") Then SendCommand("b") SayIt(RandomInterjection("PREFIX") & ", My eyes should now be blue?") ElseIf (CurrentHeard = "Please use your green eyes") Then SendCommand("g") SayIt(RandomInterjection("PREFIX") & ", My eyes should now be green!") ElseIf (CurrentHeard = "Please use your red mouth") Then SendCommand("1") SayIt(RandomInterjection("PREFIX") & ", my mouth should now be red.") ElseIf (CurrentHeard = "Please use your green mouth") Then SendCommand("2") SayIt(RandomInterjection("PREFIX") & ", my mouth should now be green. Kind of taste like grass.") ElseIf (CurrentHeard = "Please use your blue mouth") Then SendCommand("3") SayIt(RandomInterjection("PREFIX") & ", my mouth should now be a smooth blue.") ElseIf (CurrentHeard = "Goodbye " & RobotName) Then SendCommand("H") SendCommand("R") SayIt(RandomInterjection("PREFIX") & ", nice talking with you. Good bye") SendCommand("G") ListenFlag = False End If '** Save off the last contact date / time here for future reference LastContactTime = Now() End If recog.RecognizeAsync(RecognizeMode.Multiple) '** If using WIN7 use this 'recog.Enabled = True '** If using WinXP use this End Sub ' recognition failed event Public Sub recfailevent(ByVal sender As System.Object, ByVal e As RecognitionEventArgs) lblVoiceStatus.Text = "Heard but not understood" '**SayIt("Sorry, I did not understand you.") '** This isn't useful, just keeps saying it over and over lblVoiceStatus.Text = "Listening" End Sub ' form initialisation Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' need these to get British English rather than default US?? ' Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB") ' Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-GB") ' convert the word list into a grammar Dim words As New Choices(wordlist) gram = New Grammar(New GrammarBuilder(words)) recog.LoadGrammar(gram) ' add handlers for the recognition events AddHandler recog.SpeechRecognized, AddressOf Me.recevent AddHandler recog.SpeechRecognitionRejected, AddressOf Me.recfailevent '** Win XP recog enabler 'recog.Enabled = True '** Win 7+ recog enabler recog.SetInputToDefaultAudioDevice() recog.RecognizeAsync(RecognizeMode.Multiple) '** Load up the speech output myspeaker.Rate = MSSpeechSpeed myspeaker.Volume = 100 StartTime = Now() '** Log program start time for speaking InitializeForm() '** Open up /init out display form OpenComPort() '** Just send a head move command to show he/she/it is alive SendCommand("H") '** You can say any opening comments here SayIt("Hello, I am " & RobotName & ".") End Sub '** Open up the COM port '** This auto opens to the index in the variable at the top but you can select diff port if needed on the form Sub OpenComPort() Try ' Get the selected COM port's name from the combo box. If myComPort.IsOpen Then myComPort.Close() End If If Not myComPort.IsOpen Then myComPort.PortName = cmbPorts.SelectedItem.ToString ' Get the selected bit rate from the combo box. If cmbBitRate.SelectedIndex > 0 Then myComPort.BaudRate = CInt(cmbBitRate.SelectedItem) End If ' Set other port parameters. myComPort.Parity = Parity.None myComPort.DataBits = 8 myComPort.StopBits = StopBits.One myComPort.Handshake = Handshake.None myComPort.ReadTimeout = 3000 myComPort.WriteTimeout = 5000 '** This is the long term plan but need to research the solution ' AddHandler myComPort.DataReceived, AddressOf DataReceivedHandler ' Open the port. myComPort.Open() End If Catch ex As InvalidOperationException MessageBox.Show(ex.Message) SayIt(ex.Message) Catch ex As UnauthorizedAccessException MessageBox.Show(ex.Message) SayIt(ex.Message) Catch ex As System.IO.IOException MessageBox.Show(ex.Message) SayIt(ex.Message) End Try End Sub '** Load up our form the first time through and setup a few things Sub InitializeForm() Dim bitRates(9) As Integer Dim nameArray() As String ' Find the COM ports on the system. nameArray = SerialPort.GetPortNames Array.Sort(nameArray) ' Fill a combo box with the port names. cmbPorts.DataSource = nameArray cmbPorts.DropDownStyle = ComboBoxStyle.DropDownList ' Select a default port. '** Change this index to your default value to avoid resetting - see top variables cmbPorts.SelectedIndex = MyComPortIndex 'Bit rates to select from. bitRates(0) = 300 bitRates(1) = 600 bitRates(2) = 1200 bitRates(3) = 2400 bitRates(4) = 9600 bitRates(5) = 14400 bitRates(6) = 19200 bitRates(7) = 38400 bitRates(8) = 57600 bitRates(9) = 115200 'Place the bit rates in a combo box. cmbBitRate.DataSource = bitRates cmbBitRate.DropDownStyle = ComboBoxStyle.DropDownList ' Select a default bit rate. cmbBitRate.SelectedItem = 9600 Me.Text = RobotName End Sub Private Sub SendCommand(ByVal command As String) Dim response As String Try 'myComPort.WriteLine(command) '** Use this if your micro controller code is waiting for a return at the end myComPort.Write(command) '** If we WANT to get responses from the micro then enable Getcomresponse '** we get delays waiting for response otherwise If GetComResponse Then '**response = myComPort.ReadLine '** use this if you are sending a full CR/LF at the end of your response response = myComPort.ReadByte lblStatus.Text = response '** This is currently the ascii value of the return it appears, I haven't used it really Else lblStatus.Text = "OFF" End If '** this is here to allow for some responses based on return from the micro but never implemented 'Select Case response ' ' Case "0" ' ' lblStatus.Text = "LED 1 is OFF" ' ' Case "1" ' ' lblStatus.Text = "LED 1 is ON" ' ' Case Else ' 'End Select LastCommandSent.Text = command & vbCrLf & LastCommandSent.Text Catch ex As TimeoutException lblStatus.Text = "I did not get a response." 'MessageBox.Show(ex.Message) Catch ex As InvalidOperationException 'MessageBox.Show(ex.Message) lblStatus.Text = "Sorry, I have an error." Catch ex As UnauthorizedAccessException 'MessageBox.Show(ex.Message) lblStatus.Text = "I cannot access that information." End Try End Sub Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblStatus.Click End Sub '** This is for Tweeting information '** I actually use TweetyMail so you would need an account for that along with the code to send an email '** I can include that if anyone is interested '** Updated the pathing as needed though Private Sub Tweet(ByVal MyTweet) Dim start As New ProcessStartInfo start.FileName = "C:\WINDOWS\system32\cscript.exe" start.Arguments = "C:\Tweet.vbs " & Chr(34) & MyTweet & Chr(34) start.UseShellExecute = False start.RedirectStandardOutput = True start.RedirectStandardError = True Dim myproc As New Process myproc.StartInfo = start myproc.Start() Dim so As System.IO.StreamReader Dim se As System.IO.StreamReader se = myproc.StandardError so = myproc.StandardOutput myproc.WaitForExit() End Sub '** This is an external VBS as well that is not included but you can write your own '** OR add code here to read and parse the information Private Sub SayWeather() Dim start As New ProcessStartInfo start.FileName = "C:\WINDOWS\system32\cscript.exe" start.Arguments = "C:\Coding\VBScript\weather.vbs" start.UseShellExecute = False start.RedirectStandardOutput = True start.RedirectStandardError = True Dim myproc As New Process myproc.StartInfo = start myproc.Start() Dim so As System.IO.StreamReader Dim se As System.IO.StreamReader se = myproc.StandardError so = myproc.StandardOutput myproc.WaitForExit() ' MsgBox(so.ReadToEnd) ' MsgBox(se.ReadToEnd) End Sub '** This just fires off the POST to the URL in question and gets the results '** This is where my Home Automation System takes commands or status request and writes text back to say as desired Private Sub CheckURL(ByVal MyCommand) Dim result As String Try result = webClient.DownloadString(MyCommand) Catch result = "Sorry, could not get the information" End Try SayIt(result) End Sub '** the main speaking sub. Just takes a string and talks '** If using eSpeak then fires it off, otherwise the MS version '** need a waiting for piece for MS to animate things though??? Private Sub SayIt(ByVal MyString) If eSpeak Then '**************************************************************************************************************************** '** Main talking sub for eSpeak. '** After installing I copied the command line folder files to C:\eSpeck to make it easier to find '** But you can point it anywhere you need to. Dim start As New ProcessStartInfo start.FileName = "C:\espeak\espeak.exe" start.Arguments = " -p " & SpeechPitch & " -s " & SpeechSpeed & " " & Chr(34) & MyString & Chr(34) start.UseShellExecute = False start.RedirectStandardOutput = True start.RedirectStandardError = True Dim myproc As New Process myproc.StartInfo = start myproc.Start() Dim so As System.IO.StreamReader Dim se As System.IO.StreamReader se = myproc.StandardError so = myproc.StandardOutput '** Just sends whatever command you want to the micro to act like it's talking '** I have either animating action with the T/t or just open/close jaw with J/j If AnimateJaw Then SendCommand("T") Else SendCommand("J") End If myproc.WaitForExit() If AnimateJaw Then SendCommand("t") Else SendCommand("j") End If Else '** You will have to do something different here to get the status of the speaker? If AnimateJaw Then SendCommand("T") Else SendCommand("J") End If myspeaker.Speak(MyString) If WaitForSpeech Then Do Until myspeaker.State = SynthesizerState.Ready '** Just waiting for speech to complete Loop End If If AnimateJaw Then SendCommand("t") Else SendCommand("j") End If End If LastSaid.Text = MyString & vbCrLf & LastSaid.Text End Sub Private Sub ReadRss(ByVal strURL As String) '** Reads the fields out of the provided RSS feed. '** Seems to usually work but may need tweaking for other types Dim rssDoc = New XmlDocument() Try rssDoc.Load(strURL) Dim rssItems As XmlNodeList = rssDoc.SelectNodes("rss/channel/item") Dim title As String = "" Dim link As String = "" Dim upperlimit As Integer = rssItems.Count If upperlimit > 5 Then upperlimit = 5 End If If upperlimit > 0 Then Dim i As Integer = 0 While i < upperlimit Dim rssDetail As XmlNode rssDetail = rssItems.Item(i).SelectSingleNode("title") title = rssDetail.InnerText SendCommand("H") SayIt("Headline " & i + 1) SayIt(title) rssDetail = rssItems.Item(i).SelectSingleNode("link") link = rssDetail.InnerText i += 1 End While End If Catch ex As Exception SayIt("Sorry, could not connect to the Internet") End Try End Sub '** This is supposed to read the full story or link but never really used it Private Sub ReadFullRss(ByVal strURL As String) Dim rssDoc = New XmlDocument() Try rssDoc.Load(strURL) Dim rssItems As XmlNodeList = rssDoc.SelectNodes("rss/channel/item") Dim title As String = "" Dim link As String = "" Dim upperlimit As Integer = rssItems.Count If upperlimit > 5 Then upperlimit = 5 End If If upperlimit > 0 Then Dim i As Integer = 0 While i < upperlimit Dim rssDetail As XmlNode rssDetail = rssItems.Item(i).SelectSingleNode("title") title = rssDetail.InnerText SayIt("Headline " & i + 1) SayIt(title) rssDetail = rssItems.Item(i).SelectSingleNode("link") link = rssDetail.InnerText i += 1 End While End If Catch ex As Exception SayIt("Sorry, could not connect to the Internet.") End Try End Sub '** can be used to play any .wav on the local machine if you want sound effects etc Private Sub PlayWav(ByVal WavFile) Dim Sound As New System.Media.SoundPlayer() Sound.SoundLocation = WavFile 'ex.: c:\mysound.wav Sound.Load() Sound.Play() End Sub Private Sub DataReceivedHandler(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Dim sp As SerialPort = CType(sender, SerialPort) Dim indata As String = sp.ReadExisting() 'Console.WriteLine("Data Received:") 'Console.Write(indata) 'lblStatus.Text = indata 'InBoundData = indata End Sub '** Button on form to open the com port if you need to select a different one Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click OpenComPort() End Sub '** speaks the Days difference for a date type give. '** This really should be more open ended but works for me '** If you have a sub that just returns DAYS you could use it to adjust the comments to things like '** WOW its almost Christmas if days to are less than 7 or whatever '** Obviously these are hard coded and need to be updated to dynamically change... someday Private Sub SayDateDiff(ByVal SpecialDate As String) Dim MyDays As String MyDays = "" If SpecialDate = "Christmas" Then MyDays = DateDiff("d", Now(), "12/25/2015") ElseIf SpecialDate = "Halloween" Then MyDays = DateDiff("d", Now(), "10/31/2015") End If If MyDays <> "" Then SayIt(", it appears to be " & MyDays & " days until " & SpecialDate & ". ") End If End Sub Private Function RandomInterjection(ByVal InterjectionType As String) '** Just trying to add a bit more realism to the code '** You can call this to get a semi random statement back to say '** More types can be added as needed. '** Prefix is for normal responses before saying something '** Positive is for a good thing to say before '** Negative is for bad or unhappy things to say '** Wait is for when you have to go get more information to say online or similar. Dim r As Random = New Random Dim MyInterjections As String If InterjectionType = "PREFIX" Then MyInterjections = "Well,Ok,Ahh,So,Good" ElseIf InterjectionType = "POSITIVE" Then MyInterjections = "Good,Ok,That works. ,Cool beans. ,Good Deal. " ElseIf InterjectionType = "WAIT" Then MyInterjections = "Just a second. ,Lets see. ,Hang on. ,Let me see. ,This may take a second. ,Let me look that up. " ElseIf InterjectionType = "NEGATIVE" Then MyInterjections = "Sorry. ,I can't do that,No can do., Bummer." Else MyInterjections = "That was a bad interjection of " & InterjectionType & ". You really should fix that code." End If '** Split out the selected string into an array and get a 'random' return from it Dim MyInterjectionA As Array MyInterjectionA = Split(MyInterjections, ",") RandomInterjection = MyInterjectionA(CInt(Math.Ceiling(Rnd() * UBound(MyInterjectionA)))) End Function End Class