Monday, September 7, 2020

Speech to Text using Python

 

Speech to Text using Python

https://medium.com/@yashmahe2018/speech-to-text-using-python-722ecf3534fb          bt7.bcrs@gmail.com           Bantuda7

What does this program do?

This program will ask the user to state a question and will listen to the Answer that the user replies. Then it will understand what the user said and print what they said.

Step #1: Install Packages

These instructions are meant for Python 3.8, if you have an older version you can upgrade or try to follow along, but the code won’t be exactly the same. Make sure the following packages are installed:

# pip install pyaudio

# pip install speech-recognition

Step #2: Import Packages

import speech_recognition as sr

from gtts import gTTS

Step #3: Add the recognizer

mic = sr.Recognizer()

Step #4: Add a forever loop.

while True:

Step #5: Listen to what the user says

with sr.Microphone() as source:

  print("Please say something")

  audio_text = mic.listen(source)

  print("Time over, thank you")

Step #6: Understanding what the user said

try:

  usertext = mic.recognize_google(audio_text)

  print(usertext)

except:

  usertext = "Error"

No comments:

Post a Comment