This quick and easy tutorial shows you how to use python code to write a basic speech recognition program to turn your spoken words into text and then perform responses and code commands based off those words! This is a fun way to use the prebuilt python speech_recognition module and Google's word recognizer engine for easily turning spoken words into a transcribed list of words.
Happy Holidays and Merry Christmas, thank you so much to everyone in the LeMaster Tech squad for an awesome 2022!! This was the first full year for LeMaster Tech and the growth and support has been awesome.
Be sure to let me know in the comments what you hope to see more of in the next year, and don't forget to leave a like and subscribe to the channel if you haven't already. Thanks for watching and good luck with your projects!
welcome back to the channel in today's
video I'm going to show you how to use
Python for basic speech recognition and
turning speech into
[Music]
text all right so this is kind of a fun
concept uh to sort of listen to the
microphone recognize the words that
you're saying and then have the program
actually respond or do something based
off that it's the premise of how like uh
Alexa stuff and hey Siri and Okay Google
and all of those programs work they
basically use this module speech
recognition um and then on the back end
you will want to make sure you have Pi
audio you'll want both these modules
imported and run pip to install them in
your program um but then it's just a
very basic series of commands to
actually read data in from the
microphone listen to it and then process
it into text and then the program to
actually say what to do with that once
you um once you run it is pretty
straightforward so first thing we want
to do is obtain audio from mic so your
microphone uh and to do that we're just
going to make this variable recognizer
so this is our actual tool that will be
the speech recognizer comes from the
speech recognition module. capital r
recognizer and then just these empty
parentheses and then what we're going to
say is with speech
recognition. microphone so capital M
microphone as our source then what we
want to do inside of that is print the
initial command to the user that'll just
say say something like that um and so
that's how the user will know the
program's running and it's time to speak
and then we'll say audio equals and then
our recognizer variable recognizer do
listen so listen is the command to
actually listen to your microphone and
then we just want to listen to what to
the source which is what we set up the
speech recognition. microphone as our
source and now we'll say recognize the
spoken words with
Google's speech
recogition oh I think I missed an S
sorry if you guys hear any banging it
sounds like they're laying carpet in the
apartment above me um lovely okay so uh
what we want to do is we want to set all
of the words that the program has
detected equal to the recognizer Dot and
then recognize Google audio and are
different packages that you might have
seen in there when I typed in recognize
recognizer do recognize there are these
different um kind of backend tools that
you can use to recognize words I'm going
to use Google it's free it's really easy
and it's super accurate um okay so
that's creating a list of all of the
words that we have and now we're just
going to respond to spoken words all
right and what we'll say is first we'll
just check and see if we got a greeting
so if hello is in our words then let's
just
print hello to you too like that okay
it's very cool and very simple and let's
do an L if uh so L if how are you is in
the words list then we are going to
print doing great how about you okay so
we'll and then let's just throw an else
in here if uh we don't get a
uh hello or how are you then let's just
print um not sure how to respond okay
and now obviously these are some pretty
basic scenarios but uh the really the
only limitation to how you use this
software is your own creativity and what
your actual application is so you can
kind of picture the Amazon or iPhone or
Google libraries that do parse your
speech they must have massive cataloges
of different sort of if conditionals to
check what you said and what you should
do based off of that but for now let's
go ahead and run this and see if it
works so let's run easy speech to text
and it'll say say something hello
computer and let's see what we get hello
to you too how cool is that and you can
actually see um it says some things to
uh to kind of tell you what the backend
is doing result to here um and it gives
you a confidence score which means uh
it's telling you what it thinks you said
and that's it's giving you the
transcript of what it thinks that you
said but you can see all of these
different transcripts where it thinks um
that we said these different things
hello is in all of them so that's why
it's important to pick out like the key
important words there and you can see it
saw we said hello and it said hello to
you too so this is a super cool tool
it's very basic it's honestly it blows
my mind that there so many of these
amazing modules put together by like
fantastic programmers completely
available for free use in Python uh I
hope you like this video if you have any
questions about how to apply it in your
program or what a logical like next step
in a project might be just let me know
about in the comments below I hope you
found this useful uh if you did consider
leaving a like on the video subscribing
to the channel that sort of stuff helps
me out a ton I'm throwing together a few
basic uh text to speech and speech to
text videos cuz it's around the holiday
so um I hope you guys are having a merry
Christmas happy holiday season and uh as
always thanks for watching and good luck
with your projects thanks bye