Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,911 members, 7,802,961 topics. Date: Saturday, 20 April 2024 at 05:26 AM

LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! - Programming (3) - Nairaland

Nairaland Forum / Science/Technology / Programming / LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! (16758 Views)

Difference Between System Software And Application Software / Let's Learn Python-striktly Noobed!! / Let's Learn Object Oriented PHP! (2) (3) (4)

(1) (2) (3) (4) (Reply) (Go Down)

Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 4:28pm On Jan 10, 2012
I dey see as dem dey do am for TV ati Radio so make me too follow do, afterall, na my Show be this!



[center][size=18pt] A MESSAGE FROM OUR SPONSORS! [/size]grin[/center]



Oya, Final Year Engineering/Computer Engineering Students interested in creating PC controlling devices  like the PC Switch Box in the images below can send a mail to info@code4me.tk or visit www.code4me.tk for any other project topic you may be interested in.


[center][size=18pt] THE END [/size] cry[/center]



Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 4:58pm On Jan 10, 2012
Good, let's see how to write a dictionary for the computer!

First, we look at the format for writing a computer dictionary. . .

We first start by writing:

[Grammar]

This means that we want to add words to the dictionary that will form the computer's grammar set.

After this we insert "enter" key.(This is very important as it tells the computer were a line as ended in the dictionary. . .)

*PRESS ENTER*

Next comes:

langid = 1033

This tells computer that the words are from the English language.

*PRESS ENTER*

Next comes:

type=cfg

This tells the computer the type of English (In this case American English-So when you talk, you have to speak fene  grin!)

*PRESS ENTER*

Next we have:

[<Start>]

This Start indicates that we will start adding the words to the dictionary here. . .

*PRESS ENTER*

Next comes:

<start>=typethewordhere

Now this is where we will actually start adding our words to the dictionary for example, to add our first word, "I", we type this:

<start>=I

and then we

*PRESS ENTER*

Then we add the other words that will form our grammar in the same way. When we come to the last word of our grammar, we close the dictionary like this:

<start>=typelastwordhere

. . .without putting enter!


So to create a dictionary for our 4 words, this is how we will type it. . .

[Grammar]
langid = 1033
type=cfg
[<Start>]
<start>=I
<start>=Am
<start>=Very
<start>=Happy


See, it's beginning to make sense now! grin
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 5:10pm On Jan 10, 2012
Okay, what next?

We hail a Legend.

I though he would Fail in his come back, but I was put to shame by my words when he did not Fail. . .

So to a Great man. . . I salute. . .The one and only. . .






[center][size=58pt]IGWE[/size][/center]

[size=5pt]By the way I am not an arsenal fan-no offense to them, I only admire great players![/size]

Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 5:26pm On Jan 10, 2012
So after given honor to whom honor is due, what next?

Next we see how we can write our dictionary  in the VB language. . .that's where that ugly piece of code came in! But now, I believe with the given explanations, it wont be so hard for us to understand the code.

SpeechGrammer = "[Grammar]" & vbCrLf & _

We are assigning the dictionary we created above into the string called SpeechGrammer, however we have to write the dictionary in a way that VB will understand so that there wont be any syntax error from the programming language.
Because each line of the dictionary is seperated by the ENTER key, we have to add & vbCrLf & _ at the end of each statement from the dictionary. (What & vbCrLf & _ do is your take home assignment with google and not part of our topic for today!  wink )

So the dictionary written in the VB syntax looks like this:

SpeechGrammer = "[Grammar]" & vbCrLf & _
                              "langid = 1033" & vbCrLf & _
                              "type=cfg" & vbCrLf & _
                              "[<Start>]" & vbCrLf & _
                              "<start>=" & word1 & vbCrLf & _
                              "<start>=" & word2 & vbCrLf & _
                              "<start>=" & word3 & vbCrLf & _
                              "<start>=" & word4
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 5:33pm On Jan 10, 2012
A SMALL NOTE:

I could have written this:

SpeechGrammer = "[Grammar]" & vbCrLf & _
"langid = 1033" & vbCrLf & _
"type=cfg" & vbCrLf & _
"[<Start>]" & vbCrLf & _
"<start>=" & word1 & vbCrLf & _
"<start>=" & word2 & vbCrLf & _
"<start>=" & word3 & vbCrLf & _
"<start>=" & word4


as this:

SpeechGrammer = "[Grammar]" & vbCrLf & _
"langid = 1033" & vbCrLf & _
"type=cfg" & vbCrLf & _
"[<Start>]" & vbCrLf & _
"<start>=" & "I" & vbCrLf & _
"<start>=" & "Am" & vbCrLf & _
"<start>=" & "Very" & vbCrLf & _
"<start>=" & "Happy"



or even this:

SpeechGrammer = "[Grammar]" & vbCrLf & _
"langid = 1033" & vbCrLf & _
"type=cfg" & vbCrLf & _
"[<Start>]" & vbCrLf & _
"<start>=I" & vbCrLf & _
"<start>=Am" & vbCrLf & _
"<start>=Very" & vbCrLf & _
"<start>=Happy"



They are all doing the same thing, but what is the difference?
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 5:37pm On Jan 10, 2012
The difference is that the first one makes use of the variables word1,word2,word3 and word4 to store the grammar words while the other two put the words in the code straight!

Why did I use the first piece of code then and not any of the other two?
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 5:44pm On Jan 10, 2012
Because when I want to change the words in my grammar from "I,am,very,happy" to "I,am,now,hungry", I do not have to touch that ugly-looking piece of code again, I will just change:

word1 = "I"
word2 = "Am"
word3 = "Very"
word4 = "Happy"


to this:

word1 = "I"
word2 = "Am"
word3 = "Now"
word4 = "Hungry"


without touching this:

SpeechGrammer = "[Grammar]" & vbCrLf & _
"langid = 1033" & vbCrLf & _
"type=cfg" & vbCrLf & _
"[<Start>]" & vbCrLf & _
"<start>=" & word1 & vbCrLf & _
"<start>=" & word2 & vbCrLf & _
"<start>=" & word3 & vbCrLf & _
"<start>=" & word4
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 6:11pm On Jan 10, 2012
Now, let us continue with the rest of the code!

As a recap, we started with:

Dim SpeechGrammer As String

Then we went over to:

word1 = "I"
word2 = "Am"
word3 = "Very"
word4 = "Happy"


And then did the ugly bit:

SpeechGrammer = "[Grammar]" & vbCrLf & _
"langid = 1033" & vbCrLf & _
"type=cfg" & vbCrLf & _
"[<Start>]" & vbCrLf & _
"<start>=" & word1 & vbCrLf & _
"<start>=" & word2 & vbCrLf & _
"<start>=" & word3 & vbCrLf & _
"<start>=" & word4


Moving forward. . .
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 6:30pm On Jan 10, 2012
DirectSR1.GrammarFromString SpeechGrammer

Right let's analyze!

DirectSR1 is the name of the "Ear" object that we inserted on the form. (The name is automatically given to it once it is added to the form)
Now DirectSR1 represents an object and as every good student of OOP knows, objects have methods(Java) or properties(VB) and GrammarFromString is a method/property  of the object DirectSR1-If you have no idea of what I am saying, again, its not your fault

Let me speak in English, so that I will be fair to everybody!

Our "Ear" object has many characteristics/functions just as for example, a dog can bark and bite. In programming, we say that a dog is an object that has the methods/properties bark and bite. So our "Ear" object called DirectSR1 which represents the Direct Speech Recognition Tool in the VB environment, has a function or method or property called GrammarFromString

What does GrammarFromString do? 
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 6:39pm On Jan 10, 2012
GrammarFromString, ladies and gentlemen is the function that allows our "Ear" tool to "Read" a set of words stored in a "Grammer" from any given String!

So the code:

DirectSR1.GrammarFromString SpeechGrammer

Is saying:

"Hey, Ear with the fake coke bottle cover ear-ring, read the words contained in the grammar that I put inside the string called SpeechGrammer, quick no waste my time!"

Good, now let's move on. . .
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 6:47pm On Jan 10, 2012
DirectSR1.Activate

Good, this one is pretty straight forward now!

Here we see another method of the "Ear" object called DirectSR1 being used. This one is called Activate and what does it do? Yes, it actually makes the computer to start "Listening" believe it or not, for sound-any sound- from the microphone connected to your computer!

Yes and with that we end have the completed set of codes to make the computer listen for the words, "I, am, very, happy" when spoken to a microphone attached to the computer system.

So the full code is given below:
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 6:48pm On Jan 10, 2012

Dim SpeechGrammer As String


word1 = "I"
word2 = "Am"
word3 = "Very"
word4 = "Happy"
SpeechGrammer = "[Grammar]" & vbCrLf & _
                              "langid = 1033" & vbCrLf & _
                              "type=cfg" & vbCrLf & _
                              "[<Start>]" & vbCrLf & _
                              "<start>=" & word1 & vbCrLf & _
                              "<start>=" & word2 & vbCrLf & _
                              "<start>=" & word3 & vbCrLf & _
                              "<start>=" & word4

DirectSR1.GrammarFromString SpeechGrammer
DirectSR1.Activate

Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 6:53pm On Jan 10, 2012
TAKE NOTE:

This code is written inside the Command1_Click() Event Procedure of the command button that we placed on the form, so in the end we will have something like this:

Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 7:03pm On Jan 10, 2012
TAKE MORE NOTES:

Because we placed the code inside the Click() Event of the Command1 button the PC will only start listening after we have clicked on the command button when the program is running.

But if you do that now, will the computer start to type?

The answer is no! tongue

Why?

Yes, even though the computer is "listening" to us, that's about all it can do! It cannot , for example, cut into our conversation, because[b] we have not written the code[/b] for it to do so!

So how do we write the code to actually make the computer respond to what we say when we talk?

Hmm!

1 Like

Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 7:15pm On Jan 10, 2012
1. Double click on the "Ear" on the form

2. Select the PhraseFinish Option from the drop down list by the right as shown in the picture below

Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 7:42pm On Jan 10, 2012
Next you will see the page,like the one below, containing the "Ear" Tool's PhraseFinish Event handler procedure where we  can write the code for the computer to do anything we want it to do, once a sentence or phrase has been spoken completely.

It is into this event handler that we shall write the code to type the words we had placed in the dictionary.

Remember we placed a Textbox, which will was named Textbox1 by default by VB once we put it on the form.

Now this is how the PhraseFinish event handler works:

Once we say a word, say "Dog" for example, the computer will listen through the mic. If it doesn't detect anymore sound, it triggers the PhraseFinish event.

In the PhraseFinish event, the word we spoke is analyzed by the computer. It tries to see if any of the words or the word we spoke is contained  in its grammar that we gave(In this our example these are I,Am,Very,Happy) If the word we spoke is not in its grammar dictionary, then a special string variable, local only to the PhraseFinish event handler procedure, called Phrase is assigned an empty string value.

On the other hand if we said the word, "Happy", the computer will recognize it and the special variable, Phrase, will be automatically assigned the value "Happy" i.e[b] Phrase[/b] = "Happy".

In other words, if a spoken word is recognized by the computer, that word will be stored in the special variable called Phrase which only exists inside the PhraseFinish event handler procedure shown below.

1 Like

Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 7:57pm On Jan 10, 2012
Right, now to the fun part! Let's write code to type what we say on to the textbox. We can do that with a single line!

Text1.Text = Text1.Text + Phrase + " "

This means:

Take whatever text is typed in the textbox called Text1, and add it to the text inside the Phrase variable and add a space (" "wink to the end of the text and store the newly formed text back inside the Text1 textbox.

Yes, all that was said above in human language was said with just a line in computer language! smiley
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 8:01pm On Jan 10, 2012
When we add the code to the procedure, this is what we have:

1 Like

Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 8:08pm On Jan 10, 2012
That's it folks! We have done it!

Now press F5

Click the command button to make the computer to start listening for words through the mic

And say any of the words, I, am, very, happy.

You should get this:

Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 8:14pm On Jan 10, 2012
TAKE NOTE:

The efficiency of the application depends on a number of factors:

1: The quality of the microphone-the higher the quality of the mic, the better the results

2: Your pronunciation- If you pronouce fish as pish and chicken as shicken and oil as oilu, don't expect miracles to happen. The computer will only understand well spoken american english now.

3: Noise interference-This can cause the system not to hear you, or to hear a sound of an object and interpret it as a word.
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 8:22pm On Jan 10, 2012
Well, how do you like me now? cool

This shows that I am not a politician and I live up to my promises because, Yes I Can!

So try this at home and knock yourselves out! On "Some other day" (Much longer than tomorrow, thankfully), I will see how we can use this new found knowledge to make the device we created in the first lesson, turn on and off with the sound of our voice!

So till then, have a wonderful week and let's hope for the best!

See y'all! wink
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by Nobody: 10:42pm On Jan 12, 2012
Props brother. Though you haven't even scratched the surface of what you proposed to do.
You're not going to use Microsoft Voice for speech synthesis on custom hardware that isn't a windows computer cheesy
Here are the steps to accomplishing everything. . .

1) Get yourself a big breadboard. Design a system that utilizes a Microphone to convert analog sound waves to digital bits using any analog-to-digital design pattern (ADC). You should amplify the signal from the microphone before converting it to digital.

2) Depending on the quality by which you intend to process sound, determine how many bits (wires) that come out of that ADC module. So 8 bits would have 8 wires, and 16 bits would have 16 wires to work with. These will be your sound digital inputs. I'd start with 8 and maybe decide on 16 later if there is a need for enhanced precision.

3) Get a programmable IC that takes in 8 or 16 inputs and gives however many outputs. (Or multiplex those sound digital inputs to be able to go into 1 input hole if you can't find such an pIC). Now THIS is where your programming begins.

4) Programming, essentially, you have to develop a tiny neural network within that IC that weighs these sound bit inputs(what u say) according to a list of possible input templates (e.g the voice sound "Power Yourself"wink, which will trigger a command through the IC's output. For starters, this output can be an LED which simply goes On or Off whn it receives a command from the IC.

By tweaking and working things out from this starting point, you can easily achieve whatever you want.
Cheers smiley
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 4:26pm On Jan 16, 2012
Thanks for the input 2buff!

I was addressing beginners and intermediate programmers as a programmer, not as an electrical engineer! Why, you could start a tread about how to design a Speech Recognition System from the scratch using some IC chip! I am sure it will be a big hit!

To my people, stay tuned! I will be back! wink
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by sweetpawn1: 11:39pm On Jan 17, 2012
It's inevitable that I must continue this post, and that I shall! We are to create a LED lighter, connected to the PC, running windows that is activated by voice prompt to on/off itself.

Demonstrations(Not the public and street kind o! shocked Before somebody jails me for treason! shocked) with pictures will start tomorrow. . .

Good Night! wink
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by esorison(m): 1:13pm On Mar 05, 2012
please, i need the remains of the program.
esorison@yahoo.com
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by future4prof: 10:13am On Mar 15, 2012
Number_One: Nice thread. I once worked with ladder programming language. I designed an alarm trigger system that sent alert when and event occurs. E.g. A mail or sms can be sent to a house owner when his room door is opened or when power goes out. I'll go dust up those books.
@ number one, can u please help me with this ur project, i'm really interested in doing something like that. my e-mail is future4prof@yahoo.com
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by bn4al: 12:52pm On Apr 26, 2012
hi,

am actually working on the same project but i have added two control pins, DTR and RTS.

Here's the software picture am planning to control and below is my code :

the only problem am having is that, when ever DTR is switched on and i want RTS to switch on too, i get an error message.

is there any modification i can do to solved out this bug?

Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = "com4"
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort1.Open()
SerialPort1.DtrEnable = True
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SerialPort1.Open()
SerialPort1.RtsEnable = True
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
SerialPort1.Close()
SerialPort1.DtrEnable = False

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
SerialPort1.RtsEnable = False
SerialPort1.Close()
End Sub
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by hopefullman: 9:34am On Jan 16, 2013
Thanks.more of this
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by hopefullman: 11:15am On Mar 12, 2013
My location is akure.i dnt no if i cn meet any microcontroler programer here 4one on one trainin
Re: LET'S LEARN HOW TO CONTROL HOME APPLIANCES WITH SOFTWARE AND VOICE CONTROL! by seye15627(m): 4:49pm On Mar 18, 2013
sweet-pawn:
AH! ITS GOOD TO SEE THAT SOME THINGS ARE REALLY CHANGING!
HMM! MUST ATTRIBUTE IT TO THE NEW MAN IN THE PROGRAMMING SECTION BLOCK! OKAY THE ABOVE POSTS SHOWS THE CODE. SO MY FIRST TUTORIAL IS COMPLETE!
Gd work bro, weldone, please can u continue or how can i be ur student?

(1) (2) (3) (4) (Reply)

Javascript With NodeJS / Read And Generate Barcode In C# / Which Is The Best Place To Learn Programming In Nigeria?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 71
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.