Speak and computer repeats – Python and speechrecogniton

You speak the computer repeats. Wait for the “Parla” text to appear on the screen (and also the voice) and then speak. The pc will repeat what you said after a second and will write it too. We could create an interactive test where you have to answer verbally to the questions and maybe we will do it. You can find the code also in the github repository https://github.com/formazione/utilities.

Other posts like this:

import os
import time
import speech_recognition as sr
from win32com.client import Dispatch

"""
    (--------)
      Speak
        n        pythonprogramming.altervista.org
      Repeat
    (-------)

"""

s = Dispatch("SAPI.SpVoice")
r = sr.Recognizer()

def speak(text):
	s.Speak(text)

for j in range(1, 4):
	with sr.Microphone() as source:
		print("Parla")
		speak("Parla")
		audio = r.listen(source)
		time.sleep(1)
		try:
			text = r.recognize_google(audio)
			print(text)
			speak(text)
		except:
			print("Something's not working")
			text = ""


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.