Code For Virtual Assistant With GUI
Code For Virtual Assistant With GUI
import speech_recognition as sr
import pyttsx3
import time
from time import ctime
import webbrowser
import playsound
import os
import random
from gtts import gTTS
from tkinter import *
from PIL import ImageTk,Image
print('Say something...')
r = sr.Recognizer()
speaker = pyttsx3.init()
except Exception:
print('Oops something went Wrong')
#lee_voice('Oops something went Wrong')
return voice_data
def lee_voice(audio_string):
#Play audio text to voice
tts = gTTS(text=audio_string, lang='en')
r = random.randint(1, 10000000)
audio_file = 'audio-' + str(r) + '.mp3'
tts.save(audio_file)
playsound.playsound(audio_file)
print(audio_string)
os.remove(audio_file)
root = Tk()
root.title('lena')
root.geometry('520x320')
img = ImageTk.PhotoImage(Image.open('lena img.jpg'))
panel = Label(root, image=img)
panel.pack(side='right', fill='both', expand='no')
compText = StringVar()
userText = StringVar()
def clicked(self):
#BUTTON CALLING
print("working...")
voice_data = record_audio()
voice_data = voice_data.lower()
if 'who are you' in voice_data:
lee_voice('My name is Lena ')
if 'search' in voice_data:
search = record_audio('What do you want to search for ?')
url = 'https://google.com/search?q=' + search
webbrowser.get().open(url)
lee_voice('Here is what i found' + search)
if 'exit' in voice_data:
lee_voice('Thanks have a good day ')
exit()
if __name__== '__main__':
widget = Widget()
time.sleep(1)
while 1:
voice_data = record_audio()
respond(voice_data)
speaker.runAndWait()