def volumeUp(): currentVolume = Sound.current_volume() desiredVolume = int(currentVolume) + 20 if desiredVolume > 100: desiredVolume = 100 Sound.volume_set(desiredVolume)
def getCurrentVolume(): return Sound.current_volume()
def volumeDown(): currentVolume = Sound.current_volume() desiredVolume = int(currentVolume) - 20 if desiredVolume < 0: desiredVolume = 0 Sound.volume_set(desiredVolume)
def execute_cmd(cmd, voice, countries, cities, days): now = datetime.datetime.now() if cmd == "cdate": speak(str("Сейчас" + str(now.day) + "," + list_months[now.month])) elif cmd == "ctime": speak("Сейчас" + str(now.hour) + ":" + str(now.minute)) elif cmd == "course_usd": print("{} рублей".format(" ".join(convert[0].text.split()))) speak("{} рублей".format(" ".join(convert[0].text.split()))) elif cmd == "course_eur": print("{} рублей".format(" ".join(convert[2].text.split()))) speak("{} рублей".format(" ".join(convert[2].text.split()))) elif cmd == "apps": try: voice_for_apps = voice.split() voice_for_apps = voice_for_apps[1:] voice_for_apps = " ".join(voice_for_apps) USER_NAME = getpass.getuser() os.startfile( "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\{}\\{}" .format(voice_for_apps, voice_for_apps)) speak(f"Открываю {voice_for_apps}") except FileNotFoundError: try: os.startfile( "C:\\Users\\{}\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\{}" .format(USER_NAME, voice_for_apps)) speak(f"Открываю {voice_for_apps}") except FileNotFoundError: try: os.startfile( "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\{}" .format(voice_for_apps)) speak(f"Открываю {voice_for_apps}") except FileNotFoundError: try: os.startfile("C:\\Users\\{}\\Desktop\\{}".format( USER_NAME, voice_for_apps)) speak(f"Открываю {voice_for_apps}") except FileNotFoundError: print("incorrect app") elif cmd == "send": try: voice_for_vk = voice.split() voice_for_id = voice_for_vk[2] voice_for_id = vk_names[voice_for_id] voice_for_message = voice_for_vk[3:] voice_for_message = " ".join(voice_for_message) sent(voice_for_id, voice_for_message) except Exception: pass elif cmd == "note": voice = voice.split() for i in voice: if i in opts["tbr"]: voice.remove(i) for j in opts["cmds"].values(): if i in j: cmd_index = voice.index(i) voice_for_note = voice[cmd_index + 1:] voice_for_note = " ".join(voice_for_note) with open("notes.txt", "w") as file: file.writelines(voice_for_note) elif cmd == "note1": note() elif cmd == "off": check = str( input("Вы уверены что хотите завершить работу компьютера? ")) if check == "да": os.system("shutdown /p") else: pass elif cmd == "temp": try: print( get_weather( cities[voice.split()[-1]]).temperature("celsius")["temp"]) speak( get_weather( cities[voice.split()[-1]]).temperature("celsius")["temp"]) except KeyError: print("incorrect city") elif cmd == "sky": try: print(get_weather(cities[voice.split()[-1]]).detailed_status) speak(get_weather(cities[voice.split()[-1]]).detailed_status) except KeyError: print("incorrect city") elif cmd == "wind": try: print(get_weather(cities[voice.split()[-1]]).wind()) speak(get_weather(cities[voice.split()[-1]]).wind()) except KeyError: print("incorrect city") elif cmd == "if_rain": try: print(get_weather(cities[voice.split()[-1]]).rain) speak(get_weather(cities[voice.split()[-1]]).rain) except KeyError: print("incorrect city") elif cmd == "humidity": try: print(get_weather(cities[voice.split()[-1]]).humidity) speak(get_weather(cities[voice.split()[-1]]).humidity) except KeyError: print("incorrect city") elif cmd == "corona": try: covid = Covid(source="worldometers") action = covid.get_status_by_country_name( countries[voice.split()[-1]]) print("В {} {} новых случаев за сегодня".format( voice.split()[-1], action["new_cases"])) speak("В {} {} новых случаев за сегодня".format( voice.split()[-1], action["new_cases"])) except KeyError: pass elif cmd == "web_search": webbrowser.open_new_tab("https://www.google.com/search?q={}".format( "+".join(voice.split()[2:]))) elif cmd == "translate": if Translator(to_lang="ru").translate(" ".join( voice.split()[1:])) == " ".join(voice.split()[1:]): translator = Translator(from_lang="ru", to_lang="en") else: translator = Translator(from_lang="en", to_lang="ru") print(translator.translate(" ".join(voice.split()[1:]))) speak(translator.translate(" ".join(voice.split()[1:]))) elif cmd == "random": a = random.randint(1, 2) if a == 1: speak("Орёл") print("Орёл") else: speak("Решка") print("Решка") elif cmd == "print": pg.write(" ".join(voice.split()[2:]), interval="0.01") elif cmd == "close": pg.hotkey("alt", "f4") elif cmd == "sound": try: Sound.volume_set(int(voice.split()[-1])) speak("Уровень громкости установлен на {} процентов".format( int(voice.split()[-1]))) except ValueError: print("Уровень громкости указан неверно") elif cmd == "sound_switch": if Sound.current_volume() == 0: Sound.volume_set(50) else: Sound.volume_min() elif cmd == "sound_max": Sound.volume_max() speak("Уровень громкости установлен на 100 процентов") elif cmd == "wiki": try: wiki = "https://ru.wikipedia.org/wiki/{}".format("_".join( voice.split()[2:])) HEADERS = { "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng," "/;q=0.8,application/signed-exchange;v=b3;q=0.9", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/86.0.4240.198 Safari/537.36 OPR/72.0.3815.459", } def get_html(url, params=""): r = requests.get(url, headers=HEADERS, params=params) return r def get_content(html): try: soup = BeautifulSoup(html, "html.parser") items = soup.find("div", class_="mw-parser-output").find("p") return items except AttributeError: print("can`t get page content, try again") try: html = get_html(wiki) a = get_content(html.text) texts = "".join(a.find_all(text=True)) stop_point = [".", ":"] except AttributeError: pass for i in list(texts): if i in stop_point: a = len(texts.split()[:list(texts).index(i)]) if len(texts.split()[:list(texts).index(i)]) < 25: try: dot_index = [ i for i, n in enumerate(list(texts)) if n in [".", ":"] ][2] except IndexError: try: dot_index = [ i for i, n in enumerate(list(texts)) if n in [".", ":"] ][1] except IndexError: dot_index = [ i for i, n in enumerate(list(texts)) if n in [".", ":"] ][0] else: dot_index = [ i for i, n in enumerate(list(texts)) if n in [".", ":"] ][0] if len(texts.split()) == 1: print("Bruh") else: print(texts) speak("".join(list(texts)[:dot_index])) except UnboundLocalError: pass else: webbrowser.open_new_tab("https://www.google.com/search?q={}".format( "+".join(voice.split()[1:])))
elif 'sound down' in query or 'volume down' in query: key.volumedown() elif 'mute' in query or 'unmute' in query: key.volume() elif 'sound to max' in query: Sound.volume_max() speak('volume setted to 100') elif 'set sound' in query: volume.volume() elif 'volume state' in query: print("Current volume | %s" % str(Sound.current_volume())) print("Sound muted | %s" % str(Sound.is_muted())) #===================================================================== elif 'news' in query: speak('Ofcourse sir..') os.startfile("D:\\lester AI\\news.py") elif 'voice' in query: if 'female' in query: engine.setProperty('voice', voices[0].id) else: engine.setProperty('voice', voices[1].id) speak("changing voice") speak("how is this")
def Get_Volume(): return Sound.current_volume()
if (option == "2"): Sound.volume_up() continue if (option == "3"): Sound.volume_down() continue if (option == "4"): Sound.volume_min() continue if (option == "5"): Sound.volume_max() continue if (option == "6"): volume = int(input("Volume (0 - 100): ")) Sound.volume_set(volume) continue if (option == "7"): print("Current volume | %s" % str(Sound.current_volume())) print("Sound muted | %s" % str(Sound.is_muted())) print("----------------------") print("") continue if (option == "8"): exit(0)