how to make My Own Virtual Voice Assistant on python
To make your own virtual voice assistant in Python, you can use various libraries like pyttsx3, speech_recognition, and pyaudio. Here are the steps you can follow:
1. Install the required libraries: Pyttsx3, SpeechRecognition, and PyAudio. You can use `pip` to install these libraries.
2. Define the functions for text-to-speech and speech-to-text conversion using pyttsx3 and speech_recognition libraries respectively.
3. Define the main function for your virtual assistant that receives user voice input, processes it, and generates text or voice response based on the input.
4. Use conditional statements and check for user input to perform specific actions like telling the current time, sending emails, and searching the internet.
5. Test your virtual assistant by running the program and interacting with it.
Here is the sample code that you can use as a reference:
```python
import pyttsx3
import speech_recognition as sr
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User said: {query}\n")
except Exception as e:
print("Say that again please...")
return "None"
return query
if __name__ == "__main__":
speak("Hello, I am your virtual voice assistant")
while True:
query = takeCommand().lower()
if 'hello' in query:
speak('Hello There!')
if 'bye' in query:
speak('Bye-bye, see you later!')
break
```
This is just a basic example to get started; you can add more functionalities as per your requirements.