boncey / Flickr4Java

Java API For Flickr. Fork of FlickrJ
BSD 2-Clause "Simplified" License
174 stars 155 forks source link

help with code about bot #681

Closed 9ruto closed 1 year ago

9ruto commented 1 year ago

Guys, hello to everyone who can help how to make a bot written to sit waiting until the moment when you tell him the word. I have it crash after 4 seconds of waiting. import speech_recognition as sr import os import sys import webbrowser import pyttsx3 import time import getpass

poisk='' respon=0 USER_NAME = getpass.getuser()

engine = pyttsx3.init() engine.say("Приветствую тебя") engine.runAndWait()

def egor(poisk): r = sr.Recognizer() while 'егор' not in poisk: with sr.Microphone() as source: print("поиск вызова голосового помошника") audio = r.listen(source) try: poisk = r.recognize_google(audio, language="ru-RU").lower() except sr.UnknownValueError: engine = pyttsx3.init() engine.say("Ошибка распознавания голоса") engine.runAndWait() poisk = egor() return True

def command(reqest): r = sr.Recognizer()

with sr.Microphone() as source:
    engine = pyttsx3.init()
    engine.say("Говорите")
    engine.runAndWait()
    print("Говорите")
    audio = r.listen(source)

try:
    zadanie = r.recognize_google(audio, language="ru-RU").lower()
    print("Вы сказали: " + zadanie)
except sr.UnknownValueError:
    engine = pyttsx3.init()
    engine.say("Я тебя не понял")
    engine.runAndWait()
    zadanie = command()

return zadanie

def makeSomething(zadanie): if 'открыть сайт' in zadanie: engine = pyttsx3.init() engine.say("Уже открываю") engine.runAndWait() url = 'www.youtube.com' webbrowser.open(url) time.sleep(1) elif 'стоп' in zadanie: return 0 elif 'имя' in zadanie: engine = pyttsx3.init() engine.say("Меня зовут Егор") engine.runAndWait() time.sleep(1) elif 'открой дневник' in zadanie: engine = pyttsx3.init() engine.say("Уже открываю") engine.runAndWait() url = 'https://dnevnik.ru/userfeed' webbrowser.open(url) time.sleep(1) elif 'открой youtube' in zadanie: engine = pyttsx3.init() engine.say("Уже открываю") engine.runAndWait() url = 'www.youtube.com' webbrowser.open(url) time.sleep(1)

while respon!=1: poisk respon = makeSomething(command(egor(poisk))) photo_2022-11-13_15-54-36