473,505 Members | 16,940 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to activate on a magic word only

5 New Member
Hello Guys,
I am working on a home automation project which is voice based.Everything is working fine.But what i wanna do is that the recogniton becomes activated only when a magic word is spoken like "alpha gamma" and the system says"welcome master gimme ur commands" and then when i speak"switch on" then only it performs the action.If i say "switch on" before saying "alpha gamma" then it simply ignores it.
Partial code is as follows:-
Expand|Select|Wrap|Line Numbers
  1.  private void Reco_Event(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
  2.         {
  3.             txtReco.Text = Result.PhraseInfo.GetText(0, -1, true);
  4.  
  5.             //..........................Device 1------------------------------------
  6.                 if (txtReco.Text == "Device One ON")
  7.                 {
  8.  
  9.  
  10.                     //SerialPortDataReader.SendDataToPort("1");
  11.                     controller.Speak("SWITCHED ON");
  12.                     //System.Diagnostics.Process.Start(@"C:/1.wma");
  13.                     //System.Diagnostics.Process.Start("msconfig.exe");
  14.                     //------------------My Alter
  15.                     System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
  16.                     myPlayer.SoundLocation = @"c:\on.wav";
  17.                     myPlayer.Play();
  18.  
  19.                     //------------------My Alter
  20.                     //TODO: Insert Image
  21.                     Bitmap bmp = new Bitmap(@"C:/1.jpg");
  22.                     pbImage.Image = bmp;
  23.  
  24.  
  25.  
  26.  
  27.                 }
  28.                 else if (txtReco.Text == "Device One OFF")
  29.                 {
  30.  
  31.                     controller.Speak("Ha ha ha ha ah...");
  32.                     //------------------My Alter
  33.                     System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
  34.                     myPlayer.SoundLocation = @"c:\off.wav";
  35.                     myPlayer.Play();
  36.  
  37.                     //------------------My Alter
  38.                     SerialPortDataReader.SendDataToPort("5");
  39.  
  40.                 }
  41.                 //............................Device 2....................................
  42.                 else if (txtReco.Text == "Device Two ON")
  43.                 {
  44.                     SerialPortDataReader.SendDataToPort("2");
  45.  
  46.  
  47.                 }
  48.                 else if (txtReco.Text == "Device Two OFF")
  49.                 {
  50.                     SerialPortDataReader.SendDataToPort("6");
  51.  
  52.                 }
  53.                 //.....................Device 3-----------------------------------
  54.                 else if (txtReco.Text == "Device Three ON")
  55.                 {
  56.                     SerialPortDataReader.SendDataToPort("3");
  57.  
  58.                 }
  59.                 else if (txtReco.Text == "Device Three OFF")
  60.                 {
  61.                     SerialPortDataReader.SendDataToPort("7");
  62.  
  63.                 }
  64.  
Thanks in advance
-King
May 9 '10 #1
6 2075
tlhintoq
3,525 Recognized Expert Specialist
May I make a suggestion about the architecture of your project?

You don't want this system of
If "device one on",
"Device two on"
etc. if you can avoid it.

When you have 1000 devices it makes for a real mess. First your people can't remember which is device 800 and which is device 949. Second your code is mile long.

If it is possible, take the spoken phrase and study it, take it apart and then act on it with a more generic method.

You are trying to control objects in the real world. The is exactly what Object Oriented Programming was designed around. I might suggest something more along this direction.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace Winston
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         private List<RemoteDevice> myRemoteDeviceList = new List<RemoteDevice>();
  14.  
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Form1_Load(object sender, EventArgs e)
  21.         {
  22.             // Load all of my SavedRemote devices
  23.  
  24.             // Activate the 
  25.         }
  26.  
  27.         private void Reco_Event(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
  28.         {
  29.             string UserSentence = Result.PhraseInfo.GetText(0, -1, true);
  30.  
  31.             // If our format for commands is  "Device {name} {command}" let's break that down
  32.  
  33.             string[] Sentence = UserSentence.Split(' ');
  34.             if (Sentence.Length == 3)
  35.             {
  36.                 // Right sentence length. This could be a vaild instruction
  37.                 if (Sentence[0] == "Device")
  38.                 {
  39.                     // So far so good
  40.                     foreach (RemoteDevice Rosey in myRemoteDeviceList)
  41.                     {
  42.                         if (Sentence[1] == Rosey.Name)
  43.                         {
  44.                             // We found a vaild device
  45.                             string CommandResult = Rosey.DoCommand(Sentence[2]);
  46.                         }
  47.                     }
  48.                 }
  49.             }
  50.  
  51.         }
  52.     }
  53.  
  54.     class RemoteDevice
  55.     {
  56.         public string Name { get; set; }
  57.  
  58.         public RemoteDevice(string NewName)
  59.         {
  60.             Name = NewName;
  61.         }
  62.  
  63.         public virtual string DoCommand(string CommandInput)
  64.         {
  65.             switch (CommandInput.ToLower())
  66.             {
  67.                 case "on":
  68.                     return On();
  69.                     break;
  70.                 case "off":
  71.                     return Off();
  72.                     break;
  73.             }
  74.             return "Device not found";
  75.         }
  76.  
  77.         public virtual string On()
  78.         {
  79.             string Results = string.Empty;
  80.             // since each remote device has its own needs
  81.             // each instance will override this to handle its 
  82.             // own process for turning on.
  83.             return Results;
  84.         }
  85.  
  86.         public virtual string Off()
  87.         {
  88.             string Results = string.Empty;
  89.             // since each remote device has its own needs
  90.             // each instance will override this to handle its 
  91.             // own process for turning off.
  92.             return Results;
  93.         }
  94.  
  95.     }
  96. }
  97.  
  98.  
This code will process commands for 1 or 1000 RemoteDevices without growing in length.

Now you just add an instance of RemoteDevice for each device you want to control. Give each device it's own personallization. In other words, the program doesn't know much about each device. The device is responseible for itself.

Expand|Select|Wrap|Line Numbers
  1.         class WashingMachine : RemoteDevice
  2.         {
  3.  
  4.             public override string  On()
  5.             {
  6.                  //SerialPortDataReader.SendDataToPort("1");
  7.                 controller.Speak("SWITCHED ON");
  8.  
  9.                 //System.Diagnostics.Process.Start(@"C:/1.wma");
  10.                 //System.Diagnostics.Process.Start("msconfig.exe");
  11.                 //------------------My Alter
  12.                 System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
  13.                 myPlayer.SoundLocation = @"c:\on.wav";
  14.                 myPlayer.Play();
  15.                 return "Switched On";
  16.             }
  17.         }
  18.  
May 9 '10 #2
tlhintoq
3,525 Recognized Expert Specialist
As for the command password, you check it in the Reco_Event.
If the password is given, set a flag to true.
Have a timer running. If no commands are given for 30 seconds then set the flag back to false.
Then when you have a valid command sentence, first check if the flag is true. If its not, don't proceed.
May 9 '10 #3
kingabhi
5 New Member
WoW.....awesome..m really very thankful to you.
May 10 '10 #4
kingabhi
5 New Member
Hi tlhintoq,this is what I am implimenting
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using SpeechLib;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Threading;
  10.  
  11. namespace Winston
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.        private List<RemoteDevice> myRemoteDeviceList = new List<RemoteDevice>();
  16.  
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void Form1_Load(object sender, EventArgs e)
  23.         {
  24.             // Load all of my SavedRemote devices
  25.  
  26.             // Activate them 
  27.         }
  28.  
  29.         private void Reco_Event(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
  30.         {
  31.             string UserSentence = Result.PhraseInfo.GetText(0, -1, true);
  32.  
  33.             // If our format for commands is  "Device {name} {command}" let's break that down
  34.  
  35.             string[] Sentence = UserSentence.Split(' ');
  36.             if (Sentence.Length == 3)
  37.             {
  38.                 // Right sentence length. This could be a vaild instruction
  39.                 if (Sentence[0] == "Device")
  40.                 {
  41.                     // So far so good
  42.                     foreach (RemoteDevice Rosey in myRemoteDeviceList)
  43.                     {
  44.                         if (Sentence[1] == Rosey.Name)
  45.                         {
  46.                             // We found a vaild device
  47.                             string CommandResult = Rosey.DoCommand(Sentence[2]);
  48.                         }
  49.                     }
  50.                 }
  51.             }
  52.  
  53.         }
  54.     }
  55.  
  56.     class RemoteDevice
  57.     {
  58.         public string Name 
  59.         { get; 
  60.           set; 
  61.         }
  62.  
  63.         public RemoteDevice(string NewName)
  64.         {
  65.             Name = NewName;
  66.         }
  67.  
  68.         public virtual string DoCommand(string CommandInput)
  69.         {
  70.             switch (CommandInput.ToLower())
  71.             {
  72.                 case "on":
  73.                     return On();
  74.                     break;
  75.                 case "off":
  76.                     return Off();
  77.                     break;
  78.             }
  79.             return "Device not found";
  80.         }
  81.  
  82.         public virtual string On()
  83.         {
  84.             string Results = string.Empty;
  85.             // since each remote device has its own needs
  86.             // each instance will override this to handle its 
  87.             // own process for turning on.
  88.             return Results;
  89.         }
  90.  
  91.         public virtual string Off()
  92.         {
  93.             string Results = string.Empty;
  94.             // since each remote device has its own needs
  95.             // each instance will override this to handle its 
  96.             // own process for turning off.
  97.             return Results;
  98.         }
  99.  
  100.     }
  101. }
  102.  
  103. class WashingMachine : RemoteDevice
  104. {
  105.  
  106.     public override string On()
  107.     {
  108.         //SerialPortDataReader.SendDataToPort("1");
  109.         controller.Speak("SWITCHED ON");
  110.  
  111.         //System.Diagnostics.Process.Start(@"C:/1.wma");
  112.         //System.Diagnostics.Process.Start("msconfig.exe");
  113.         //------------------My Alter
  114.         System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
  115.         myPlayer.SoundLocation = @"c:\on.wav";
  116.         myPlayer.Play();
  117.         return "Switched On";
  118.     }
  119. }
  120.  
But i am getting an error
Error 1 The type or namespace name 'RemoteDevice' could not be found (are you missing a using directive or an assembly reference?)
Please Help.
May 10 '10 #5
tlhintoq
3,525 Recognized Expert Specialist
Move the WashingMachine class inside the namespace of Winston.
As you have it, it is totally outside the namespace, Thus it has no idea of class RemoteDevice.
May 10 '10 #6
kingabhi
5 New Member
This time i am getting
Expand|Select|Wrap|Line Numbers
  1. Error    1    'SpeechDiff.RemoteDevice.Name.get' must declare a body because it is not marked abstract or extern
  2. Error    2    'SpeechDiff.RemoteDevice.Name.set' must declare a body because it is not marked abstract or extern
  3.  
Please help..i am a newbie.
May 10 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1593
by: wandaring | last post by:
here's my problem If a visitor comes to visit my site and puts in his / her browser www . mysite.com/Ceciliasfirstpage.html (excluding the space) I want Ceciliasfirstpage.html to be generated...
3
11277
by: Brian Kwan | last post by:
Project Description: Develop a web application to help manage sale operations. There is a function that to generate a report using data in database, which is a Word document on server and let user...
1
352
by: Bill Short | last post by:
I would like to print a report (or reports) from Access based on the Word document I have open. For instance, the Word doc I have open is called 10-789-65.doc. From Word, I would like to open...
3
2293
by: IMS.Rushikesh | last post by:
Hi Friends, I am having a problem to set a background color of any selected Word in MS-Word. Only few default (nearly 16 colors) are allow to set as Background color in MS-Word. But i want to...
0
1070
by: Luis Esteban Valencia Muņoz | last post by:
I am trying to access a word document, preferably on the client side in my intranet. The document is stored on the sever which is also a mapped network drive. I have been able to access and save...
3
2381
by: Scupper | last post by:
I am working on adapting a process currently handled by VBA functions in a Word template, moving to a VB.NET app that calls Word only when necessary to manipulate documents (essentially, it is...
2
3374
by: Patrik Birgersson | last post by:
Hi there! I've been trying for days to find a solution anywhere on the web to this problem and I hope you might be able to sort me out. I want to use PHP and COM to set and read values of MS...
22
2242
by: liya.tansky | last post by:
Hello, I'm developing an intranet (win XP, .NET 2, Visual Studio 2005, Microsoft.Office.Interop.Word.dll in references) and needed to implement find-replace in word doc before sending letter and...
2
1426
by: poolboi | last post by:
hi all, if i got a string say i feel like going to swim today if i have input say "swim" and i wanna compare it with the sentence above, it will return true and go on to the rest of the...
6
5904
by: empiresolutions | last post by:
Im trying to make a naughty word filter. It removes bad words fine, but instances where there is a bad word found in the text like "assist" and "asses" get caught in the filter as well. Strangely...
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.