mirror of
https://github.com/Dasemu/DesktopAssistant.git
synced 2026-02-04 04:30:20 +00:00
Merge branch 'main' of https://github.com/Harsha200105/DesktopAssistant into Harsha200105-main
This commit is contained in:
90
actions.py
90
actions.py
@@ -3,10 +3,7 @@ import webbrowser
|
||||
|
||||
import pyttsx3
|
||||
import requests
|
||||
|
||||
engine = pyttsx3.init("sapi5")
|
||||
voices = engine.getProperty("voices")
|
||||
engine.setProperty("voice", voices[0].id)
|
||||
import configparser
|
||||
|
||||
|
||||
def search_engine_selector(config):
|
||||
@@ -19,7 +16,9 @@ def search_engine_selector(config):
|
||||
elif config['DEFAULT']['search_engine'] == 'Youtube':
|
||||
return "https://www.youtube.com"
|
||||
else:
|
||||
# If none of default ones selected
|
||||
# If none of default ones selected triesto fetch https://example.com
|
||||
# to see if its valid as search engine and if its valid it uses it.
|
||||
# If not valid it uses Google.
|
||||
try:
|
||||
if requests.get(
|
||||
f"https://{config['DEFAULT']['search_engine'].lower()}.com",
|
||||
@@ -63,3 +62,84 @@ def wish_me(master):
|
||||
speak("Good Evening" + master)
|
||||
|
||||
# speak("Hey I am Jarvis. How may I help you")
|
||||
|
||||
|
||||
def change_rate(query, take_command):
|
||||
try:
|
||||
rate = query.split('to')[-1]
|
||||
engine.setProperty('rate', int(rate))
|
||||
speak("¿Do you want to keep this config?")
|
||||
answer = take_command()
|
||||
if answer == "yes":
|
||||
config['DEFAULT']['rate'] = rate
|
||||
with open('config.ini', 'w') as configfile:
|
||||
config.write(configfile)
|
||||
else:
|
||||
pass
|
||||
except Exception:
|
||||
speak("Invalid value. Please try again.")
|
||||
|
||||
|
||||
def change_voice(query, take_command):
|
||||
try:
|
||||
voice = query.split('to')[-1]
|
||||
if voice == "male":
|
||||
engine.setProperty('voice', voices[0].id)
|
||||
speak("¿Do you want to keep this config?")
|
||||
if take_command() == "yes":
|
||||
config['DEFAULT']['voice'] = 'Male'
|
||||
with open('config.ini', 'w') as configfile:
|
||||
config.write(configfile)
|
||||
else:
|
||||
pass
|
||||
|
||||
elif voice == "female":
|
||||
engine.setProperty('voice', voices[1].id)
|
||||
speak("¿Do you want to keep this config?")
|
||||
answer = take_command()
|
||||
print(answer)
|
||||
if answer == "yes":
|
||||
config['DEFAULT']['voice'] = 'Female'
|
||||
with open('config.ini', 'w') as configfile:
|
||||
config.write(configfile)
|
||||
else:
|
||||
pass
|
||||
else:
|
||||
speak("Invalid value. Please try again.")
|
||||
except Exception:
|
||||
speak("Invalid value. Please try again.")
|
||||
|
||||
|
||||
def change_volume(query, take_command):
|
||||
try:
|
||||
volume = query.split('to')[-1]
|
||||
engine.setProperty('volume', int(volume)/100)
|
||||
speak("¿Do you want to keep this config?")
|
||||
answer = take_command()
|
||||
if answer == "yes":
|
||||
config['DEFAULT']['volume'] = volume
|
||||
with open('config.ini', 'w') as configfile:
|
||||
config.write(configfile)
|
||||
else:
|
||||
pass
|
||||
except Exception:
|
||||
speak("Invalid value. Please try again.")
|
||||
|
||||
|
||||
engine = pyttsx3.init("sapi5")
|
||||
voices = engine.getProperty("voices")
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
|
||||
if config['DEFAULT']['voice'] == 'Male':
|
||||
engine.setProperty('voice', voices[0].id)
|
||||
else:
|
||||
engine.setProperty('voice', voices[1].id)
|
||||
|
||||
try:
|
||||
engine.setProperty('rate', int(config['DEFAULT']['rate']))
|
||||
engine.setProperty('volume', int(config['DEFAULT']['volume'])/100)
|
||||
|
||||
except Exception:
|
||||
speak("Bad config. Setting up default values")
|
||||
|
||||
Reference in New Issue
Block a user