Speech Recognition using Visual Studio: Determining the BNA

My original title was Stochastic Determination of BNA, but seriously who would read that.   Also, I was giving some thought to one of my managers (it takes many people to manage me) who is going through an eye operation, and it gave me an idea on how to do speech recognition.  This app works with the microphone on your computer, so you don’t need to buy another one.  And really it is kind of fun.  I also included some history because that is part of my creative process.  Since I wrote it, I included it.

But now what is BNA? 

This is short for Blahoxyribonucleic Annunciations, and occurs when someone is uses more jargon in a conversation then a culture finds acceptable.  I do it, you do it, we all do it.  Unless you never speaker or are a good listener.

Just how can we perform an analysis of the amount of BNA in any conversation.  We will need a way to do speech recognition and a grammar of jargon.

So my first thought was how to analyze speech, after all to determine Blahoxyribonucleic Annunciations, we need to determine the conversational level of jargon, and jargon is a special set of grammar.  We will need a jargon library, MS Word has a setting that will check for jargon, so that means that there must be a library of jargon somewhere, jargon implies that we need to think about grammar. And I think a little bit about the history of speech synthesis.  After all, a large part of spying is listening to conversations on telecommunications systems.  And since this is a short blog, there will be quite a bit of short cuts.

As usual that was more complicated then needed, but I wandered off to https://research.microsoft.com and found an old paper titled: “Reduction of Speech Spectra by Analysis-by-Synthesis Techniques”, 1961 where a good definition of speech is given.

“The generally accepted theory speech production views the speech wave as the result of acoustic excitation of the vocal tract by one or more sources.”

Analysis by synthesis is a technique that would require far too much computation, but it did lead to other processes with functionality based in this concept.

So in 1961 the software/hardware diagram looked the drawing below, and the word punch, means that there was a system that would actually punch holes in a paper tape.  Really.  But note that there is the idea that the input would be converted from analog to digital, which in 1961 was a difficult process.

image

 

Now moving forward into the present, how could you design a system that would be able to detect the Blahoxyribonucleic Annunciations in a conversation, for instance, could you use the Windows Phone to act to report on the level of BNA in a conversation?  Not at this time Windows Phone Projects do NOT allow the use of System.Speech, so this has to be a Windows only program.

Finally this means that in speech recognition we will need a grammar.  Our diagram might look like the following

image

Then I did a search on speech and found the following article with code. 

Speech Recognition: https://msdn.microsoft.com/en-us/library/hh361633.aspx

Create Grammars Using GrammarBuilder: https://msdn.microsoft.com/en-us/library/hh361640.aspx 

What you will see when everything is working:

image 

 

With a slight modification I have created a “Blah” counter, when you run the code, if you use the words jargon or acronym the counter doesn’t increment (the form doesn’t do anything, it’s what the example used).  You have to press ok each time for the code to run.

To make this run, you will have to add a reference to the System.Speech (I show this below the code if you need to review how to do that):

Code Snippet

  1. using System;

  2. using System.Speech.Recognition;

  3. using System.Windows.Forms;

  4.  

  5. namespace WindowsFormsApplication3

  6. {

  7.     public partial class Form1 : Form

  8.     {

  9.         SpeechRecognizer sr;

  10.         int bnaCounter=0;

  11.  

  12.         public Form1()

  13.         {

  14.             InitializeComponent();

  15.         }

  16.  

  17.         private void Form1_Load(object sender, EventArgs e)

  18.         {

  19.             // Create a new SpeechRecognizer instance.

  20.             sr = new SpeechRecognizer();

  21.  

  22.             // Create a simple grammar that recognizes "red", "green", or "blue".

  23.             Choices jargon_grammar = new Choices();

  24.             jargon_grammar.Add(new string[] { "jargon", "blah", "acroymn" });

  25.            

  26.  

  27.             // Create a GrammarBuilder object and append the Choices object.

  28.             GrammarBuilder gb = new GrammarBuilder();

  29.             gb.Append(jargon_grammar);

  30.  

  31.             // Create the Grammar instance and load it into the speech recognizer.

  32.             Grammar g = new Grammar(gb);

  33.             sr.LoadGrammar(g);

  34.  

  35.             // Register a handler for the SpeechRecognized event.

  36.             sr.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sr_SpeechRecognized);

  37.         }

  38.  

  39.         // Create a simple handler for the SpeechRecognized event.

  40.         void sr_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)

  41.         {

  42.             if (e.Result.Text=="blah")

  43.             {

  44.                 bnaCounter++;

  45.             }

  46.             MessageBox.Show(e.Result.Text + " Number of blahs " + bnaCounter);

  47.  

  48.  

  49.         }

  50.  

  51.     }

  52. }

 

Adding a reference to System.Speech, first right click reference under your project:

image

From the dialog box that appears (yours may appear different than mine) select System.Speech:

image

 

 

And if you read all the way down here, this was a difficult blog to pull together, at the start I had no idea that it would work and it did.  Nice!

My other blogs can be seen at:

Take a look at my colleagues blogs!