Halo habr! Nama saya Gleb Pryakhin, saya berumur 14 tahun, saya menulis asisten suara dengan python 3 dan mengkompilasinya menjadi exe.
( Tautan ke versi yang dikompilasi )
( Tautan ke sumber )
Saya meminta Anda untuk menguji asisten tersebut dan mengajukan pertanyaan kepadanya,
jika Anda memiliki pertanyaan atau ingin menulis untuk mendukung: di komentar di bawah posting, atau melalui email. mail glebilic@gmail.com.
Mari kita mulai dengan kodenya! Pertama, mari impor modul:
import pyttsx3
import os
import time
import datetime
import speech_recognition as sr
import random
import webbrowser
import sounddevice as sd
Untuk menambahkan suara, unduh dan instal 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()
Dan apakah ada kesalahan? Atau, apa yang akan dilakukan bot jika tidak menemukan jawaban? Itulah yang. Omong-omong, asisten mengerti bahwa dia tidak menjalankan perintah apa pun selama siklus jika variabel 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()
Tetap hanya menjadi "nol", tidak ada ini, tetapi variabel sehingga tidak ada operasi berulang:
an = ""
if cikl == 2:
cikl = 0
cont = ""
Itu saja kode saya, jika Anda menggunakannya, harap sertakan tautan ke posting ini di kode atau antarmuka.
Saya menunggu saran, ide dan kritik Anda di komentar di bawah posting dan di surat: glebilic@gmail.com.
Sampai!