'''
Online Python Compiler.
Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.
'''
#Module to convert text to speech
import pyttsx3 as ttos
#Module to convert speech to text and pyaudio is installed with this
import speech_recognition as sr
#Gets the information of current driver
#assist is an isntance
assist = ttos.init()
#Get the current value of the rate, volume, voice property in pyttsx3
#Integer speech rate in words per minute, and by default 200 word per minute
#rate = assist.getProperty('rate')
#print(rate)
#String indentifier of the active voice
#voice = assist.getProperty('voice')
#print(voice)
#List of pyttsx3.voice.Voice descriptor objec
voices = assist.getProperty('voices')
#print(voices)
#Floating point volume in the range of 0.0. to 1.0 inclusive
#volume = assist.getProperty('volume')
#print(volume)
assist.setProperty('voice', voices[1].id)
assist.setProperty('rate', 150)
#print(voices)
assist.say("Hey hello..., My name is July")
#Blocks while processing all currently queued commands
assist.runAndWait()
#Recognizer is a class which helps to get the information from the source (Eg: Microphone)
reg = sr.Recognizer()
with sr.Microphone() as source:
#It even captures the low voice with the below 10000 setting
reg.energy_threshold = 10000
#It cancels the noise around me
reg.adjust_for_ambient_noise(source, duration = 1)
print("Listening......")
# It listens from the source and saves it in a variable called audio
audio = reg.listen(source)
# It converts the audio to text
text = reg.recognize_google(audio)
print(text)