Answers for "speech_recognition python"

2

python speech recognition

#pip install SpeechRecognition
#in case of error use 'pip install pyaudio' or...
#in case of error use 'pip install pipwin' then 'pipwin install pyaudio'
#if error continued you may need to use python 3.6 or lower as the latest 
#python may not support pyaudio... 
import speech_recognition as sr
import pyttsx3

#audio of system to respond
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
engine.setProperty('rate',180)

def speak(audio):
    engine.say(audio)
    engine.runAndWait()

# simple function to recognise speech from user
def takecommand():
    #it takes microphone input and returns string output
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print('Listening.....')
        r.pause_threshold = 1
        r.energy_threshold = 4000
        audio = r.listen(source)

    try:
        print('Recognising...')
        query = r.recognize_google(audio, language='en-in')
        print('User Said : ' , query)

    except Exception as e:
        print('exception : ',e)

        speak("Sorry, I didn't hear that, Say that again Please")
        return "None"
    return query
while True:
  query = takecommand() # whatever user says will be stored in this variable
  print("The Test got in program is : "+query)
Posted by: Guest on May-26-2021
5

python speech recognition

import speech_recognition as sr

def take_command():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print('Listening...')
        r.pause_threshold = 1
        r.energy_threshold = 50
        audio = r.listen(source)

    try:
        print('Recognizing...')
        qry = r.recognize_google(audio, language='en-in')
        print(f"user said: {qry}n")
        
#     if any error occurs this line will run
    except Exeption as e:
    # if you don't want to print the error comment the bottom line
        print(e)
        print('Say that again pleasen')
        return 'None'

    return qry
  
if __name__ == '__main__':
	while True:
  		qry = takecommand().lower()
  
# now you can use the takecommand function where you want to recognize speech
# And please experiment with the above code 
# like what pause_threshold and energy_threshold do 
///////////---  *HAPPYCODING*  ---///////////
Posted by: Guest on February-25-2021
0

how to fix speech recognition in python

import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:                # use the default microphone as the audio source
    audio = r.listen(source)                   # listen for the first phrase and extract it into audio data

try:
    print("You said " + r.recognize(audio))    # recognize speech using Google Speech Recognition
except LookupError:                           # speech is unintelligible
    print("Could not understand audio")
Posted by: Guest on May-05-2020
-1

speech recognition in python

from easySpeech import speech
a=speech.speech('google')
print(a)
Posted by: Guest on June-01-2021
1

how to use speech recognition in python

import speech_recognition as sr
recognizer = sr.Recognizer()
microphone = sr.Microphone()
with microphone as source:
    recognizer.adjust_for_ambient_noise(source)
    audio = recognizer.listen(source)
    command = recognizer.recognize_google(audio)
    print(command)
Posted by: Guest on October-26-2021

Code answers related to "speech_recognition python"

Python Answers by Framework

Browse Popular Code Answers by Language