Answers for "speech recognition in python code"

19

python text to speech

The best library because you dont have to save the
text file or open the file to start the speech

pip install pyttsx3

import pyttsx3
engine = pyttsx3.init()
engine.say("Hello world")
engine.runAndWait()
Posted by: Guest on August-28-2020
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

Code answers related to "speech recognition in python code"

Python Answers by Framework

Browse Popular Code Answers by Language