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,570 points
1,517 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,300 points
772 views
0 votes
0 answers

Please help me to install speech recognition in VS code

I got this type of error ERROR: Could ...READ MORE

Oct 4, 2021 in Python by Edureka
• 120 points
1,038 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
592 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 11, 2018 in Python by anonymous
628 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,074 views
0 votes
1 answer
+5 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,790 points
3,496 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
632 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
1,769 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP