Notepad Online
import speech_recognition as sr
import pyttsx3
import requests
import webbrowser
import os
engine = pyttsx3.init()
voices = engine.getProperty("voices")
for voice in voices:
if "brazil" in voice.name.lower() or "portuguese" in voice.name.lower():
engine.setProperty("voice", voice.id)
engine.setProperty("rate", 180)
def falar(texto):
print("Portal:", texto)
engine.say(texto)
engine.runAndWait()
def ouvir():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Ouvindo...")
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
texto = r.recognize_google(audio, language="pt-BR")
print("Você:", texto)
return texto.lower()
except:
return ""
def perguntar_ia(pergunta):
url = "http://localhost:11434/api/generate"
data = {
"model": "phi3:mini",
"prompt": pergunta,
"stream": False
}
try:
response = requests.post(url, json=data)
resultado = response.json()
if "response" in resultado:
return resultado["response"]
if "message" in resultado:
return resultado["message"]["content"]
return "Não consegui gerar resposta."
except Exception as erro:
return "Erro ao acessar a inteligência artificial."
def executar_comando(texto):
if "abrir youtube" in texto:
falar("Abrindo YouTube")
webbrowser.open("https://youtube.com")
elif "abrir google" in texto:
falar("Abrindo Google")
webbrowser.open("https://google.com")
elif "abrir spotify" in texto:
falar("Abrindo Spotify")
os.system("start spotify")
elif "abrir chrome" in texto:
falar("Abrindo Chrome")
os.system("start chrome")
else:
resposta = perguntar_ia(texto)
falar(resposta)
print("Portal 3.1 iniciado.")
falar("Portal online.")
while True:
texto = ouvir()
if texto == "":
continue
if "portal" in texto:
comando = texto.replace("portal", "").strip()
if comando == "":
falar("Sim?")
else:
executar_comando(comando)
Este é um notepad compartilhado. Crie o seu, sem cadastro.