avatarJ3

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

6503

Abstract

and <a href="https://pypi.org/project/SpeechRecognition/">SpeechRecognitions</a> from google.</p><p id="96ae">Then, obtain audio from the microphone.</p><p id="28cb">And finaly, Recognize speech using Google Speech Recognition</p><p id="5da1">Say something and wait the answer 👈</p><div id="72a3"><pre>!pip <span class="hljs-keyword">install</span> pyaudio !pip <span class="hljs-keyword">install</span> SpeechRecognition</pre></div><div id="d774"><pre><span class="hljs-attribute">Collecting</span> pyaudio <span class="hljs-attribute">Using</span> cached PyAudio-<span class="hljs-number">0</span>.<span class="hljs-number">2</span>.<span class="hljs-number">12</span>-cp39-cp39-win_amd64.whl (<span class="hljs-number">163</span> kB) <span class="hljs-attribute">Installing</span> collected packages: pyaudio <span class="hljs-attribute">Successfully</span> installed pyaudio-<span class="hljs-number">0</span>.<span class="hljs-number">2</span>.<span class="hljs-number">12</span> <span class="hljs-attribute">Collecting</span> SpeechRecognition <span class="hljs-attribute">Using</span> cached SpeechRecognition-<span class="hljs-number">3</span>.<span class="hljs-number">8</span>.<span class="hljs-number">1</span>-py2.py3-none-any.whl (<span class="hljs-number">32</span>.<span class="hljs-number">8</span> MB) <span class="hljs-attribute">Installing</span> collected packages: SpeechRecognition <span class="hljs-attribute">Successfully</span> installed SpeechRecognition-<span class="hljs-number">3</span>.<span class="hljs-number">8</span>.<span class="hljs-number">1</span></pre></div><p id="6b93">The code:</p><div id="1711"><pre><span class="hljs-keyword">import</span> speech_recognition <span class="hljs-comment"># Obtain audio from the microphone</span> recognizer = speech_recognition.Recognizer() <span class="hljs-keyword">with</span> speech_recognition.Microphone() <span class="hljs-keyword">as</span> source: <span class="hljs-built_in">print</span>(<span class="hljs-string">"Say something:"</span>) audio = recognizer.listen(source)</pre></div><div id="74fa"><pre><span class="hljs-comment"># Recognize speech using Google Speech Recognition</span> <span class="hljs-built_in">print</span>(<span class="hljs-string">"You said:"</span>) <span class="hljs-built_in">print</span>(recognizer.recognize_google(audio))</pre></div><div id="fc11"><pre><span class="hljs-attribute">Say something</span><span class="hljs-punctuation">:</span> <span class="hljs-attribute">You said</span><span class="hljs-punctuation">:</span> Shoe Stop</pre></div><h1 id="eef3">Here we mixed the two codes above and see what happened!</h1><p id="b796">To test it please run as much as you like!</p><p id="3e64">Three words or sets of words must exist in the sentence spoken and captured by the microphone:</p><div id="ef42"><pre>“HELLO” “HOW <span class="hljs-keyword">ARE</span> YOU” “GOODBYE”</pre></div><p id="8014">The code:</p><div id="163b"><pre><span class="hljs-keyword">import</span> speech_recognition <span class="hljs-comment"># Obtain audio from the microphone</span> recognizer = speech_recognition.Recognizer() <span class="hljs-keyword">with</span> speech_recognition.Microphone() <span class="hljs-keyword">as</span> source: <span class="hljs-built_in">print</span>(<span class="hljs-string">"Say something:"</span>) audio = recognizer.listen(source)</pre></div><div id="2b2a"><pre><span class="hljs-comment"># Recognize speech using Google Speech Recognitionwords = recognizer.recognize_google(audio)</span></pre></div><div id="d1c8"><pre><span class="hljs-comment"># Respond to speech</span> <span class="hljs-keyword">if</span> <span class="hljs-string">"hello"</span> <span class="hljs-keyword">in</span> words: <span class="hljs-built_in">print</span>(<span class="hljs-string">"Hello to you too!"</span>) elif <span class="hljs-string">"how are you"</span> <span class="hljs-keyword">in</span> words: <span class="hljs-built_in">print</span>(<span class="hljs-string">"I am well, thanks!"</span>) elif <span class="hljs-string">"goodbye"</span> <span class="hljs-keyword">in</span> words: <span class="hljs-built_in">print</span>(<span class="hljs-string">"Goodbye to you too!"</span>) <span class="hljs-keyword">else</span>: <span class="hljs-built_in">print</span>(<span class="hljs-string">"Huh?"</span>)</pre></div><div id="c59e"><pre><span class="hljs-built_in">Say</span> something: Goodbye <span class="hljs-keyword">to</span> you too!</pre></div><h1 id="a551">Now say what’s your name</h1><div id="adde"><pre><span class="hljs-keyword">import</span> re <span class="hljs-keyword">import</span> speech_recognition <span class="hljs-comment"># Obtain audio from the microphone</span> recognizer = speech_recognition.Recognizer() <span class="hljs-keyword">with</span> speech_recognition.Microphone() <span class="hljs-keyword">as</span> source: <span class="hljs-built_in">print</span>(<span class="hljs-string">"Say something:"</span>) audio = recognizer.listen(source)</pre></div><div id="9329"><pre><span class="hljs-comment"># Recognize speech using Google Speech Recognition</span> <span class="hljs-attr">words</span> = recognizer.recognize_google(audio)</pre></div><div id="c23f"><pre><span class="hljs-comment"># Respond to speech</span> matches = re.search(<span class="hljs-string">"my name is (.*)"</span>, words) <span class="hljs-keyword">if</span> matches: <span class="hljs-built_in">print</span>(f<span class="hljs-string">"Hey, {matches[1]}."</span>) <span class="hljs-keyword">else</span>: <span class="hljs-built_in">print</span>(<span class="hljs-string">"Hey, you."</span>)</pre></div><div id="6fb8"><pre><span class="hljs-attribute">Say</span> something: <span class="hljs-attribute">Hey</span>, J-<span class="hljs-number">3</span>.</pre></div><h1 id="0b08">Tech 4 # Speech Recognition in Python</h1><p id="7f06">visit: <a href="https://pypi.org/project/pyttsx3/">https://pypi.org/project/pyttsx3/</a></p><p id="797c">It Supports multiple TTS engines, including Sapi5, nsss, and espeak.</p><div id="c175"><pre>!pip <span class="hljs-keyword">install</span> pyttsx3</pre></div><div id="aad1"><pre>Requirement already <span class="hljs-name">satisfied</span>: pyttsx3 <span class="hljs-keyword">in</span> <span class="hljs-name">c</span>:\users\giljr\anaconda3\lib\site-packages (<span class="hljs-number">2.90</span>) Requirement already <span class="hljs-name">satisfied</span>: comtypes <span cl

Options

ass="hljs-keyword">in</span> <span class="hljs-name">c</span>:\users\giljr\anaconda3\lib\site-packages (<span class="hljs-keyword">from</span> pyttsx3) (<span class="hljs-number">1.1</span><span class="hljs-number">.10</span>) Requirement already <span class="hljs-name">satisfied</span>: pypiwin32 <span class="hljs-keyword">in</span> <span class="hljs-name">c</span>:\users\giljr\anaconda3\lib\site-packages (<span class="hljs-keyword">from</span> pyttsx3) (<span class="hljs-number">223</span>) Requirement already <span class="hljs-name">satisfied</span>: pywin32 <span class="hljs-keyword">in</span> <span class="hljs-name">c</span>:\users\giljr\appdata\roaming\python\python39\site-packages (<span class="hljs-keyword">from</span> pyttsx3) (<span class="hljs-number">303</span>)</pre></div><p id="9219">The code:</p><div id="9495"><pre>import pyttsx3 engine = pyttsx3<span class="hljs-selector-class">.init</span>() engine<span class="hljs-selector-class">.say</span>(<span class="hljs-string">"hello, world"</span>) engine<span class="hljs-selector-class">.runAndWait</span>()</pre></div><p id="d158">You will hear the sentence written above on your computer speakers.</p><div id="8b0f"><pre>import pyttsx3 <span class="hljs-attribute">engine</span> <span class="hljs-operator">=</span> pyttsx3.init() <span class="hljs-attribute">name</span> <span class="hljs-operator">=</span> input(<span class="hljs-string">"What's your name? "</span>) engine.say(f<span class="hljs-string">"hello, {name}"</span>) engine.runAndWait()</pre></div><div id="35d6"><pre>What<span class="hljs-symbol">'s</span> your name? j3</pre></div><p id="cbf9">And finally:</p><div id="4581"><pre>import pyttsx3 engine = pyttsx3<span class="hljs-selector-class">.init</span>() engine<span class="hljs-selector-class">.say</span>(<span class="hljs-string">"This was CS50"</span>) engine<span class="hljs-selector-class">.say</span>(<span class="hljs-string">"That's it!"</span>) engine<span class="hljs-selector-class">.say</span>(<span class="hljs-string">"Thanks to: DAVID MALAN from HAVARD CS50 COURSE"</span>) engine<span class="hljs-selector-class">.runAndWait</span>()</pre></div><p id="5e2e">The credits goes to:</p><div id="f0e9"><pre><span class="hljs-function"><span class="hljs-title">print</span><span class="hljs-params">(<span class="hljs-string">"Credits Goes To: HAVARD CS50 COURSE - DAVID MALAN - https://youtu.be/d6ZcOxZYh4Y"</span>)</span></span></pre></div><div id="32db"><pre>Credits Goes <span class="hljs-keyword">To</span>: HAVARD CS50 COURSE - DAVID MALAN - https:<span class="hljs-comment">//youtu.be/d6ZcOxZYh4Y</span></pre></div><p id="37df">👉<a href="https://github.com/giljr/my_jupyter_notebook">Github</a> (PPY-12)</p><h1 id="927f">Related Posts</h1><p id="752b"><b>00</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/lambda-in-python-421b0c18e825"><b>Lambda in Python </b></a>— Python Lambda Desmistification</p><p id="0338"><b>01</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/send-emails-using-python-jupyter-notebook-94d14a5a5655"><b>Send Email in Python</b></a> — Using Jupyter Notebook — How To Send Gmail In Python</p><p id="1680"><b>02</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/automate-your-email-marketing-with-python-f0d68234b789"><b>Automate Your Email With Python & Outlook</b></a><b> </b>— How To Create An Email Trigger System in Python</p><p id="6474"><b>03</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/manipulating-files-with-python-3f9a781287e9"><b>Manipulating Files With Python</b></a> — Manage Your Lovely Photos With Python!</p><p id="2fdd"><b>04</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/pandas-dataframe-advanced-48f83a5b097f"><b>Pandas DataFrame Advanced </b></a>— A Complete Notebook Review</p><p id="a7c2"><b>05</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/is-this-leap-year-python-calendar-3d1a61f2c4a7"><b>Is This Leap Year? Python Calendar</b> </a>— How To Calculate If The Year Is Leap Year and How Many Days Are In The Month</p><p id="5797"><b>06</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/list-comprehension-in-python-c22c4b0a6a8a"><b>List Comprehension In Python </b></a>— Locked-in Secrets About List Comprehension</p><p id="8bf0"><b>07</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/graphs-in-python-b7d243737b77"><b>Graphs — In Python </b></a>— Extremely Simple Algorithms in Python</p><p id="32eb"><b>08</b>#Episode#PurePythonSeries — <a href="https://readmedium.com/decorator-in-python-62c00f7e818"><b>Decorator in Python</b></a> — How To Simplifying Your Code And Boost Your Function</p><p id="5553">12#Episode#PurePythonSeries — <b>Advanced Python Technologies </b>— qrcode, Speech Recognition in Python, Google Speech Recognition #PurePythonSeries (this one)</p><p id="9645"><b>13#</b>Episode#PurePythonSeries — <a href="https://readmedium.com/advanced-python-technologies-ii-33d2d6888583"><b>Advanced Python Technologies II</b></a> — qFace Recognition w/ Jupyter Notebook & Ubuntu</p><p id="6511"><b>14#</b>Episode#PurePythonSeries — <a href="https://readmedium.com/advanced-python-technologies-iii-ac92cd677e5e"><b>Advanced Python Technologies III</b> </a>— Face Recognition w/ Colab</p><p id="7074"><b>15#</b>Episode#PurePythonSeries — <a href="https://readmedium.com/iss-tracking-project-python-af4b5fa47a28"><b>ISS Tracking Project</b></a> — Get an Email alert when International Space Station (ISS) is above of us in the sky, at night</p><p id="e7b2"><b>16#</b>Episode#PurePythonSeries — <a href="https://readmedium.com/using-gemini-chat-on-collab-2626fb035176"><b>Using Gemini Chat on Collab</b></a> — Random Number Generation, List Manipulation & Rock-Paper-Scissors Game Implementations</p><p id="f2f9"><b>17#</b>Episode#PurePythonSeries — Python — <a href="https://readmedium.com/python-basics-2ce557a80f42"><b>Basics</b> </a>— Functions, OOP, file handling, calculator, loops</p><p id="0d6e"><b>18#</b>Episode#PurePythonSeries — Python — <a href="https://readmedium.com/efficient-file-handling-in-python-0d952971ebc9"><b>Efficient File Handling in Python</b></a><b> </b>— Best Practices and Common Methods</p><p id="08db"><b>19#</b>Episode#PurePythonSeries — Python — <a href="https://readmedium.com/how-to-securely-save-credentials-in-python-dd5c6983741a"><b>How To Securely Save Credentials in Python</b> </a>— Like API tokens, passwords, or other sensitive data</p></article></body>

Advanced Python Technologies I

qrcode, Speech Recognition in Python, Google Speech Recognition #PurePythonSeries — Episode #12

Tech 1 # qrcode

visit: https://pypi.org/project/qrcode/

What is a QR Code?

A Quick Response code is a two-dimensional pictographic code used for its fast readability and comparatively large storage capacity

#### In the code below:
First we install qrcode directly from jupyter notebook.
Then, after importing the lib, we generate a qrcode, and save it as PNG - Portable Network Graphics

Install the lib:

!pip install qrcode
Collecting qrcode
  Downloading qrcode-7.3.1.tar.gz (43 kB)
     -------------------------------------- 43.5/43.5 kB 353.8 kB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Requirement already satisfied: colorama in c:\users\giljr\appdata\roaming\python\python39\site-packages (from qrcode) (0.4.4)
Building wheels for collected packages: qrcode
  Building wheel for qrcode (setup.py): started
  Building wheel for qrcode (setup.py): finished with status 'done'
  Created wheel for qrcode: filename=qrcode-7.3.1-py3-none-any.whl size=40401 sha256=21157d8580f2ede48dc47666675f5a87ae0c15d4aeb7b102d281040a35194f18
  Stored in directory: c:\users\giljr\appdata\local\pip\cache\wheels\72\8d\d4\18b60cd6cda7fd6832229ded41aa505cee22e22f7f47ea97ea
Successfully built qrcode
Installing collected packages: qrcode
Successfully installed qrcode-7.3.1

Run this code:

import os
import qrcode
# Generate QR code
img = qrcode.make("https://medium.com/jungletronics")
# Save as file
img.save("qr.png", "PNG")
# Open file
os.system("open qr.png")
1
Please visit jungletronics on media dot com 😉

Tech 2 # Simplified Answering Machine

To test it please run as much as you like!

Three words or sets of words must exist in the sentence spoken and captured by the microphone:

“HELLO”
“HOW ARE YOU”
“GOODBYE”

And wait for the answer 😉

The code:

# Recognizes a greeting
# Get input
words = input("Say something!\n").lower()
# Respond to speech
if "hello" in words:
    print("Hello to you too!")
elif "how are you" in words:
    print("I am well, thanks!")
elif "goodbye" in words:
    print("Goodbye to you too!")
else:
    print("Huh?")
Say something!
hello
Hello to you too!

Tech 3 # Speech Recognition in Python

There are several technologies available on the market. Let's bring the google solution, shall we?
How to Convert Speech to Text in Python
CMU Sphinx (offline)
Google Speech Recognition
Google Cloud Speech API
Wit.ai
Microsoft Bing Voice Recognition
Houndify API
IBM Speech To Text
Snowboy Hotword Detection (offline)

In the code below:

First we install pyaudio and SpeechRecognitions from google.

Then, obtain audio from the microphone.

And finaly, Recognize speech using Google Speech Recognition

Say something and wait the answer 👈

!pip install pyaudio
!pip install SpeechRecognition
Collecting pyaudio
  Using cached PyAudio-0.2.12-cp39-cp39-win_amd64.whl (163 kB)
Installing collected packages: pyaudio
Successfully installed pyaudio-0.2.12
Collecting SpeechRecognition
  Using cached SpeechRecognition-3.8.1-py2.py3-none-any.whl (32.8 MB)
Installing collected packages: SpeechRecognition
Successfully installed SpeechRecognition-3.8.1

The code:

import speech_recognition
# Obtain audio from the microphone
recognizer = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
    print("Say something:")
    audio = recognizer.listen(source)
# Recognize speech using Google Speech Recognition
print("You said:")
print(recognizer.recognize_google(audio))
Say something:
You said:
Shoe Stop

Here we mixed the two codes above and see what happened!

To test it please run as much as you like!

Three words or sets of words must exist in the sentence spoken and captured by the microphone:

“HELLO”
“HOW ARE YOU”
“GOODBYE”

The code:

import speech_recognition
# Obtain audio from the microphone
recognizer = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
    print("Say something:")
    audio = recognizer.listen(source)
# Recognize speech using Google Speech Recognitionwords = recognizer.recognize_google(audio)
# Respond to speech
if "hello" in words:
    print("Hello to you too!")
elif "how are you" in words:
    print("I am well, thanks!")
elif "goodbye" in words:
    print("Goodbye to you too!")
else:
    print("Huh?")
Say something:
Goodbye to you too!

Now say what’s your name

import re
import speech_recognition
# Obtain audio from the microphone
recognizer = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
    print("Say something:")
    audio = recognizer.listen(source)
# Recognize speech using Google Speech Recognition
words = recognizer.recognize_google(audio)
# Respond to speech
matches = re.search("my name is (.*)", words)
if matches:
    print(f"Hey, {matches[1]}.")
else:
    print("Hey, you.")
Say something:
Hey, J-3.

Tech 4 # Speech Recognition in Python

visit: https://pypi.org/project/pyttsx3/

It Supports multiple TTS engines, including Sapi5, nsss, and espeak.

!pip install pyttsx3
Requirement already satisfied: pyttsx3 in c:\users\giljr\anaconda3\lib\site-packages (2.90)
Requirement already satisfied: comtypes in c:\users\giljr\anaconda3\lib\site-packages (from pyttsx3) (1.1.10)
Requirement already satisfied: pypiwin32 in c:\users\giljr\anaconda3\lib\site-packages (from pyttsx3) (223)
Requirement already satisfied: pywin32 in c:\users\giljr\appdata\roaming\python\python39\site-packages (from pyttsx3) (303)

The code:

import pyttsx3
engine = pyttsx3.init()
engine.say("hello, world")
engine.runAndWait()

You will hear the sentence written above on your computer speakers.

import pyttsx3
engine = pyttsx3.init()
name = input("What's your name? ")
engine.say(f"hello, {name}")
engine.runAndWait()
What's your name? j3

And finally:

import pyttsx3
engine = pyttsx3.init()
engine.say("This was CS50")
engine.say("That's it!")
engine.say("Thanks to: DAVID MALAN from HAVARD CS50 COURSE")
engine.runAndWait()

The credits goes to:

print("Credits Goes To: HAVARD CS50 COURSE - DAVID MALAN - https://youtu.be/d6ZcOxZYh4Y")
Credits Goes To: HAVARD CS50 COURSE - DAVID MALAN - https://youtu.be/d6ZcOxZYh4Y

👉Github (PPY-12)

Related Posts

00#Episode#PurePythonSeries — Lambda in Python — Python Lambda Desmistification

01#Episode#PurePythonSeries — Send Email in Python — Using Jupyter Notebook — How To Send Gmail In Python

02#Episode#PurePythonSeries — Automate Your Email With Python & Outlook — How To Create An Email Trigger System in Python

03#Episode#PurePythonSeries — Manipulating Files With Python — Manage Your Lovely Photos With Python!

04#Episode#PurePythonSeries — Pandas DataFrame Advanced — A Complete Notebook Review

05#Episode#PurePythonSeries — Is This Leap Year? Python Calendar — How To Calculate If The Year Is Leap Year and How Many Days Are In The Month

06#Episode#PurePythonSeries — List Comprehension In Python — Locked-in Secrets About List Comprehension

07#Episode#PurePythonSeries — Graphs — In Python — Extremely Simple Algorithms in Python

08#Episode#PurePythonSeries — Decorator in Python — How To Simplifying Your Code And Boost Your Function

12#Episode#PurePythonSeries — Advanced Python Technologies — qrcode, Speech Recognition in Python, Google Speech Recognition #PurePythonSeries (this one)

13#Episode#PurePythonSeries — Advanced Python Technologies II — qFace Recognition w/ Jupyter Notebook & Ubuntu

14#Episode#PurePythonSeries — Advanced Python Technologies III — Face Recognition w/ Colab

15#Episode#PurePythonSeries — ISS Tracking Project — Get an Email alert when International Space Station (ISS) is above of us in the sky, at night

16#Episode#PurePythonSeries — Using Gemini Chat on Collab — Random Number Generation, List Manipulation & Rock-Paper-Scissors Game Implementations

17#Episode#PurePythonSeries — Python — Basics — Functions, OOP, file handling, calculator, loops

18#Episode#PurePythonSeries — Python — Efficient File Handling in Python — Best Practices and Common Methods

19#Episode#PurePythonSeries — Python — How To Securely Save Credentials in Python — Like API tokens, passwords, or other sensitive data

Qr Code
Stt
Speech Recognition
Google Speech To Text
Bots
Recommended from ReadMedium