Created
April 26, 2020 17:40
-
-
Save idcesares/7a0071080b73abb706436ec75c248073 to your computer and use it in GitHub Desktop.
Usando a biblioteca pyttsx3 para text-to-speech no Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Instalar o pyttsx3 com o comando abaixo: | |
| # pip install pyttsx3 | |
| import pyttsx3 | |
| # Iniciando a biblioteca na variável engine | |
| engine = pyttsx3.init() | |
| # Função pronta para uso | |
| def speak(speech): | |
| engine.say(speech) | |
| engine.runAndWait() | |
| # Só chamar a função speak() | |
| speak("Isto é um Quadrado!") | |
| speak("Isto é um Triângulo!") | |
| speak("Isto é uma Estrela!") |
SOU SOU O JARVIS A SUA INTELIGÊNCIA ARTIFICIAL
COMO POSSO AJUDÁ-LO?
import speech_recognition as sr
import pyttsx3
Inicializa o reconhecedor de voz e o motor de texto-para-fala
recognizer = sr.Recognizer()
engine = pyttsx3.init()
def speak(text):
engine.say(text)
engine.runAndWait()
Função para ouvir e reconhecer o comando de voz
def listen():
with sr.Microphone() as source:
print("Diga algo:")
audio = recognizer.listen(source)
try:
command = recognizer.recognize_google(audio)
print(f"Você disse: {command}")
return command
except sr.UnknownValueError:
print("Não entendi o que você disse")
return None
Comando simples de interação
while True:
command = listen()
if command:
if 'olá' in command:
speak("Olá! Como posso ajudar?")
elif 'sair' in command:
speak("Até logo!")
break
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Olá senhor