Hallo habr! Mein Name ist Gleb Pryakhin, ich bin 14 Jahre alt, ich habe einen Sprachassistenten in Python 3 geschrieben und ihn zu exe zusammengestellt.
( Link zur kompilierten Version )
( Link zur Quelle )
Ich bitte Sie, den Assistenten zu testen und ihm Fragen zu stellen.
Wenn Sie Fragen haben oder an den Support schreiben möchten: in den Kommentaren unter dem Beitrag oder per E-Mail. mail glebilic@gmail.com.
Beginnen wir mit dem Code! Importieren wir zunächst die Module:
import pyttsx3
import os
import time
import datetime
import speech_recognition as sr
import random
import webbrowser
import sounddevice as sd
Laden Sie RHvoice herunter und installieren Sie es, um Stimmen hinzuzufügen.
- tts, . num123 = , tts1 = .
f = open("sp.txt", "r")
num123 = f.read(1000)
num123 = int(num123)
f.close
f = open("tts.txt", "r")
tts1 = int(f.read(1))
f.close()
#
tts = pyttsx3.init()
speak_engine = pyttsx3.init()
voices = speak_engine.getProperty('voices')
speak_engine.setProperty('voice', voices[tts1].id)
:
os.system('cls' if os.name == 'nt' else 'clear')
print(" 2.0 ALFA \nBy \n2021 \n-...")
name , ! , ! :
f = open('name.txt', 'r')
if f.read(1) == "":
os.system('cls' if os.name == 'nt' else 'clear')
tts.say(" , , , , . . ?")
tts.runAndWait()
r = sr.Recognizer()
with sr.Microphone(device_index = 1) as source:
print(' ')
r.adjust_for_ambient_noise(source, duration=0.5) #
print('...')
audio = r.listen(source)
print(' ')
try:
query = r.recognize_google(audio, language = 'ru-RU')
name = query.lower()
print(f' : {query.lower()}')
except:
print('-')
tts.say(" ")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" .")
tts.runAndWait()
r = sr.Recognizer()
with sr.Microphone(device_index = 1) as source:
print(' ')
r.adjust_for_ambient_noise(source, duration=0.5) #
print('...')
audio = r.listen(source)
print(' ')
try:
query = r.recognize_google(audio, language = 'ru-RU')
ver = query.lower()
print(f' : {query.lower()}')
except:
print('-')
if "" in ver or "" in ver:
f = open('name.txt', 'w')
f.write(name.title())
f.close()
tts.say("! !")
tts.runAndWait()
else:
tts.say(" ")
tts.runAndWait()
name = input(" : ")
tts.say("! !")
tts.runAndWait()
f = open('name.txt', 'w')
f.write(name.title())
f.close()
, - , " ", :
if num123 == 0:
tts.say(" : :")
tts.runAndWait()
tts.say(" ")
tts.runAndWait()
:
#
f = open("sp.txt", "w")
num123 = num123 + 1
num123 = str(num123)
num123 = f.write(num123)
f.close
#
f = open('name.txt', 'r')
name = f.read(10)
r = random.randint(1,10)
r, elif` cont, :
cont = ""
if r == 1:
tts.say(" ")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" ?")
tts.runAndWait()
elif r == 2:
tts.say("")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" ?")
tts.runAndWait()
elif r == 3:
tts.say(" ")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" ?")
tts.runAndWait()
elif r == 4:
tts.say(" ")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" ?")
tts.runAndWait()
cont = ("")
elif r == 5:
tts.say(" ")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" ?")
tts.runAndWait()
cont = ""
elif r == 6:
tts.say("")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" ?")
tts.runAndWait()
cont = ""
elif r == 7:
tts.say(" ")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" ?")
tts.runAndWait()
elif r == 8:
tts.say("")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" ?")
tts.runAndWait()
cont = ""
elif r == 9:
tts.say(" ")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" ?")
tts.runAndWait()
elif r == 10:
tts.say(" ")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" ?")
tts.runAndWait()
:
while True:
cikl = cikl + 1
ca = 0
ra = random.randint(1,10)
an = ""
#
r = sr.Recognizer()
with sr.Microphone(device_index = 1) as source:
print(' ')
r.adjust_for_ambient_noise(source, duration=0.5) #
print('...')
audio = r.listen(source)
print(' ')
try:
query = r.recognize_google(audio, language = 'ru-RU')
an = query.lower()
print(f' : {query.lower()}')
except:
print('-')
"", cont? "" " ?", "" " ?", , .
#
if "" in an and len(an) == 2 or "" in an or "- " in an:
ca = 1
if cont == "":
f = open('email.txt', 'r')
if f.read(1) == "":
tts.say(" , ! .")
tts.runAndWait()
a = 1
while True:
v = input(" .")
f = open('email.txt', 'w')
if "https" in v:
web = v
f.write(web)
f.close()
break
tts.say(" ")
f = open('email.txt', 'r')
web = f.read(97)
f.close()
tts.runAndWait()
webbrowser.open(web)
elif cont == "":
tts.say(", ")
tts.runAndWait()
webbrowser.open('https://www.youtube.com/')
elif cont == "":
tts.say(" ")
tts.runAndWait()
webbrowser.open('https://okko.tv/')
elif cont == "":
tts.say(" !")
tts.runAndWait()
webbrowser.open('https://www.youtube.com/watch?v=E3rH3KdVWcc')
elif cont == "":
tts.say(", ")
tts.runAndWait()
webbrowser.open('https://www.youtube.com/channel/UCy0uukwm4dOSFCGyfp8g2sw')
else:
tts.say(" .")
tts.runAndWait()
. 1 :
:
elif " " in an or "" in an:
ca = 1
tts.say(" ")
tts.runAndWait()
webbrowser.open("https:/vk.com")
, :
elif " " in an:
ca = 1
tts.say(" ")
tts.runAndWait()
tts.say(an[an.find("")+3:])
tts.runAndWait()
sear = an[an.find("")+3:]
webbrowser.open("https://www.google.com/search?q=" + sear)
, , :
elif "" in an:
ca = 1
f = open('email.txt', 'r')
if f.read(1) == "":
tts.say(" , ! .")
tts.runAndWait()
a = 1
while True:
v = input(" .")
f = open('email.txt', 'w')
if "https" in v:
web = v
f.write(web)
f.close()
break
:
:
elif " " in an:
ca = 1
os.system(' ')
tts.say(" ")
tts.runAndWait()
tts.say(name) # .
tts.runAndWait()
:
elif " " in an or " " in an:
ca = 1
tts.say("")
tts.runAndWait()
tts.say(name)
tts.runAndWait()
tts.say(" . .")
tts.runAndWait()
for i in range(10):
os.system('cls' if os.name == 'nt' else 'clear')
print(" ", i, ".")
time.sleep(1)
print("...")
time.sleep(1)
os.system('shutdown -s')
. , :
#
elif "" in an or "" in an:
ca = 1
f = open("z1.txt", "a")
if an[len(""):] == "":
tts.say(" ! , .")
tts.runAndWait()
print("! !")
else:
tts.say(" , , ?")
tts.runAndWait()
an45 = an[len(""):] + ","
f.write(an45)
f.close()
elif "" in an:
ca = 1
f = open("z1.txt", "r")
if f.read(1) == "":
tts.say(" . , .")
tts.runAndWait()
else:
st = f.read()
print(st)
tts.say(" :")
tts.runAndWait()
tts.say(st)
tts.runAndWait()
tts.say(" , .")
tts.runAndWait()
f.close()
elif " " in an or " " in an:
ca = 1
print(" ?")
tts.say(" ? .")
tts.runAndWait()
#
r = sr.Recognizer()
with sr.Microphone(device_index = 1) as source:
print(' ')
r.adjust_for_ambient_noise(source, duration=0.5) #
print('...')
audio = r.listen(source)
print(' ')
try:
query = r.recognize_google(audio, language = 'ru-RU')
an = query.lower()
print(f' : {query.lower()}')
except:
print('-')
if an == "" or "" in an or "" in an:
ca = 1
print("...")
f = open("z1.txt", "w")
f.write("")
tts.say(" .")
tts.runAndWait()
else:
print("...")
tts.say(" , . ...")
tts.runAndWait()
f.close()
:
elif "" in an:
ca = 1
tts1 = input(" :")
f = open("tts.txt", "w")
f.write(tts1)
f.close()
elif "" in an or "" in an:
ca = 1
tts.say(", . ")
tts.runAndWait()
an4925479864 = input("[] enter: ")
tts.say("-, ?.")
tts.runAndWait()
. , , " " " ".
elif " " in an:
ca = 1
tts.say(" , ?")
tts.runAndWait()
f = open('dialogset.txt', 'w')
f.write("1")
f.close()
elif " " in an:
ca = 1
tts.say(" .")
tts.runAndWait()
f = open('dialogset.txt', 'w')
f.write("0")
f.close()
f = open('dialogset.txt', 'r')
an4897987 = f.read(1)
f.close()
if an4897987 == "1":
rsm = random.randint(1,3)
if "" in an or "" in an:
ca = 1
if rsm == 1:
tts.say(", ?.")
tts.runAndWait()
elif rsm == 2:
tts.say(" .")
tts.runAndWait()
elif rsm == 3:
tts.say(".")
tts.runAndWait()
# `
elif "1" in an or "2" in an:
ca = 1
if rsm == 1:
tts.say("1 ")
tts.runAndWait()
elif rsm == 2:
tts.say("2 .")
tts.runAndWait()
elif rsm == 3:
tts.say("3 ")
tts.runAndWait()
elif "" in an and "" in an:
ca = 1
if rsm == 1:
tts.say(" - , , , -.")
tts.runAndWait()
elif rsm == 2:
tts.say(" ! . . ?")
tts.runAndWait()
cont = ""
cikl = 0
elif rsm == 3:
tts.say(" ! ?")
tts.runAndWait()
elif "" in an or "" in an:
ca = 1
if rsm == 1:
tts.say(" , ?")
tts.runAndWait()
elif rsm == 2:
tts.say(" , .")
tts.runAndWait()
elif rsm == 3:
tts.say(" .")
tts.runAndWait()
Und wenn es einen Fehler gibt? Oder was macht der Bot, wenn er keine Antwort findet? Das ist, was. Der Assistent versteht übrigens, dass er während des Zyklus keinen Befehl ausgeführt hat, wenn die Variable ca = 0 ist.
if an == "":
print("")
ca = 1
if ca == 0:
print("")
if ra == 1 or ra ==2:
tts.say(" ...")
tts.runAndWait()
elif ra == 3 or ra == 4:
tts.say(" .")
tts.runAndWait()
elif ra == 5 or ra == 6:
tts.say(" .")
tts.runAndWait()
elif ra == 7 or ra == 8:
tts.say(" , ")
tts.runAndWait()
elif ra == 9 or ra == 10:
tts.say(" .")
tts.runAndWait()
Es bleibt nur "Null", es gibt nicht diese, sondern eine Variable, so dass es keine wiederholten Operationen gibt:
an = ""
if cikl == 2:
cikl = 0
cont = ""
Das ist mein ganzer Code. Wenn Sie ihn verwenden, fügen Sie bitte einen Link zu diesem Beitrag in den Code oder die Benutzeroberfläche ein.
Ich warte auf Ihren Rat, Ihre Ideen und Ihre Kritik in den Kommentaren unter dem Beitrag und in der Mail: glebilic@gmail.com.
Tschüss!