Bonjour habr! Je m'appelle Gleb Pryakhin, j'ai 14 ans, j'ai écrit un assistant vocal en python 3 et l'ai compilé en exe.
( Lien vers la version compilée )
( Lien vers la source )
Je vous demande de tester l'assistant et de lui poser des questions,
si vous avez des questions ou souhaitez écrire au support: dans les commentaires sous le post, ou par email. mail glebilic@gmail.com.
Commençons avec le code! Tout d'abord, importons les modules:
import pyttsx3
import os
import time
import datetime
import speech_recognition as sr
import random
import webbrowser
import sounddevice as sd
Pour ajouter des voix, téléchargez et installez RHvoice.
- 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()
Et s'il y a une erreur? Ou que fera le bot s'il ne trouve pas de réponse? C'est ce que. D'ailleurs, l'assistant comprend qu'il n'a exécuté aucune commande pendant le cycle si la variable ca = 0.
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()
Il ne reste plus qu'à "zéro", il n'y a pas ça, mais une variable pour qu'il n'y ait pas d'opérations répétées:
an = ""
if cikl == 2:
cikl = 0
cont = ""
C'est tout mon code, si vous l'utilisez, veuillez inclure un lien vers ce message dans le code ou l'interface.
J'attends vos conseils, idées et critiques dans les commentaires sous le post et dans le mail: glebilic@gmail.com.
Jusqu'à!