Skip to content

Instantly share code, notes, and snippets.

@idcesares
Created April 26, 2020 17:40
Show Gist options
  • Select an option

  • Save idcesares/7a0071080b73abb706436ec75c248073 to your computer and use it in GitHub Desktop.

Select an option

Save idcesares/7a0071080b73abb706436ec75c248073 to your computer and use it in GitHub Desktop.
Usando a biblioteca pyttsx3 para text-to-speech no Python
# 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!")
@lucasrochadavi61-alt
Copy link

Com vídeo e voz

@r85858216-alt
Copy link

Olá senhor

@r85858216-alt
Copy link

SOU SOU O JARVIS A SUA INTELIGÊNCIA ARTIFICIAL

@r85858216-alt
Copy link

COMO POSSO AJUDÁ-LO?

@mcbacana07-droid
Copy link

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