Speech recognition code - Python

0 votes
I have been assigned a project in python where I am suppossed to create speech recognition logic. Can somebody provide a code or resources which would be helpful?

Thanks in advance!
Oct 3, 2019 in Python by Hannah
• 18,420 points
586 views

1 answer to this question.

0 votes

Hi Hannah, 

Have a look at this code:

import speech_recognition as sr
import webbrowser as wb

r1 = sr.Recognizer()
r2 = sr.Recognizer()
r3 = sr.Recognizer()

with sr.Microphone() as source:
    print('[search edureka: search youtube]')
    print('speak now')
    audio = r3.listen(source)

if 'edureka' in r2.recognize_google(audio):
    r2 = sr.Recognizer()
    url = '<a href="https://www.edureka.co/">https://www.edureka.co/</a>'
    with  sr.Microphone() as source:
        print('search your query')
        audio = r2.listen(source)

        try:
            get = r2.recognize_google(audio)
            print(get)
            wb.get().open_new(url + get)
        except sr.UnknownValueError:
            print('error')
        except sr.RequestError as e:
            print('failed'.format(e))

if 'video' in r1.recognize_google(audio):
    r1 = sr.Recognizer()
    url = '<a href="https://www.youtube.com/results?search_query=">https://www.youtube.com/results?search_query=</a>'
    with sr.Microphone() as source:
        print('search for a video')
        audio = r2.listen(source)

        try:
            get = r1.recognize_google(audio)
            print(get)
            wb.get().open_new(url + get)

        except sr.UnknownValueError:
            print('could not understand')
        except sr.RequestError as e:
            print('failed to get results'.format(e))

This code basically listens to your speech and does a google search on it. Have a look at this blog for a detailed explanation: https://www.edureka.co/blog/speech-recognition-python/

answered Oct 3, 2019 by Waseem

Related Questions In Python

0 votes
1 answer

Speech Recognition and Python

you can use https://pypi.python.org/pypi/pygsr $> pip install pygsr example ...READ MORE

answered Oct 29, 2018 in Python by SDeb
• 13,250 points
288 views
0 votes
1 answer

Normal Python code equivalent to given list comprehension

You can try this code list1=[] for i in ...READ MORE

answered Jun 8, 2018 in Python by jain12
• 170 points
98 views
0 votes
1 answer

GAE: python code to check if i'm on dev_appserver or deployed to appspot

I don't know if you still need ...READ MORE

answered Sep 10, 2018 in Python by anonymous
107 views
+1 vote
1 answer

How to use GUI that comes with Python to test your code?

Hey @alex0809, When your testing a website ...READ MORE

answered Sep 24, 2018 in Python by Vardhan
• 13,180 points
179 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,459 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,800 points
1,090 views
0 votes
1 answer

How to encode Python source code?

Python allows you to encode the source ...READ MORE

answered May 14, 2019 in Python by Jimmy
95 views
0 votes
1 answer

Python code Tic Tac Toe game

You could use random.shuffle from random import shuffle players ...READ MORE

answered May 28, 2019 in Python by Idam
945 views