<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Buddhi Ashen</title>
    <description>The latest articles on DEV Community by Buddhi Ashen (@buddhiashen).</description>
    <link>https://dev.to/buddhiashen</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F890320%2F7af1065a-f074-4846-a400-0fd5f17fa448.png</url>
      <title>DEV Community: Buddhi Ashen</title>
      <link>https://dev.to/buddhiashen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/buddhiashen"/>
    <language>en</language>
    <item>
      <title>Create simple speech recognition program</title>
      <dc:creator>Buddhi Ashen</dc:creator>
      <pubDate>Sun, 07 Aug 2022 04:09:39 +0000</pubDate>
      <link>https://dev.to/buddhiashen/create-simple-speech-recognition-program-53ga</link>
      <guid>https://dev.to/buddhiashen/create-simple-speech-recognition-program-53ga</guid>
      <description>&lt;p&gt;if you are an ironman fan you probably know about his two AI systems called 'Jarvis' &amp;amp; 'friday'. tony use speech recognition to give commands to his AI systems.&lt;/p&gt;

&lt;p&gt;how to do it in the real world, is it posibble? the answer is yes it is. in here we use python to make a program that recognizes your speech and prints it out as text. let's get to work.&lt;/p&gt;

&lt;p&gt;requirements for this project :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Python 3&lt;/li&gt;
&lt;li&gt;Python speech recognition module.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;now let's code.&lt;/p&gt;

&lt;p&gt;to install the python speech recognition model, type this in your terminal&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install SpeechRecognition
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and we use the microphone as our input method. in python to use a microphone we need another module name called "Pyaudio". to install that type this in your terminal.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install PyAudio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;now all set. we have to write some code to make a speech recognition system.&lt;/p&gt;

&lt;p&gt;first of all import all necessary libraries.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import speech_recognition as sr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;now initialize the recognizer.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;listener = sr.Recognizer()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;now we use an error handler in case there is an error. we use to &lt;code&gt;try&lt;/code&gt; and &lt;code&gt;except&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try:
    with sr.Microphone() as source:
        print('listning...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        print(command)

except:
    pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;​&lt;/p&gt;

&lt;p&gt;Now, let's break down this one by one;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;with sr.Microphone() as source:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;this means with the speech recognition model (we rename speech recognition as "sr" in the beginning) gets the microphone as a source of input.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print('listning...')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;print out the text "listing"&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;voice = listener.listen(source)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;get the user's&lt;/p&gt;

&lt;p&gt;voice as input through the microphone&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;command = listener.recognize_google(voice)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;now we pass the user's voice into the google speech recognizer, by the way, we need an internet connection for this project.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print(command)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;now print out what the user said&lt;/p&gt;

&lt;p&gt;the output will be like this :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PS C:\Users\User\Desktop\python practice\ai&amp;gt; &amp;amp; "C:/Program Files/Python39/python.exe" "c:/Users/User/Desktop/python practice/ai/speech-recognition.py"
listning...
hello
PS C:\Users\User\Desktop\python practice\ai&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;congratulations, now you build your own voice recognition system by using python. if you face any kind of trouble or error please inform me. about that. I like to help you with that.&lt;/p&gt;

&lt;p&gt;the complete code :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import speech_recognition as sr

listener = sr.Recognizer()
try:
    with sr.Microphone() as source:
        print('listning...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        print(command)

except:
    pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
