An Interest In:
Web News this Week
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
February 15, 2022 05:27 am GMT
Original Link: https://dev.to/preetsuthar/python-text-to-speech-converter-30c2
Python Text to Speech Converter.
Speech recognition is very useful! It can be used in so many applications or programs like it can be used for home automation systems, artificial intelligence, etc. so in this article, you'll learn how to make basic text-to-speech programs using python.
Installation required
Python (it's very obvious. to install python go to https://www.python.org/downloads/ and download python)
Speech Recognition module
pip install SpeechRecognition
pyAudio module
pip install pyAudio
NOTE: if you get errors while installing pyAudio check out this question from StackOverflow Here
pyttsx3 module
pip install pyttsx3
Speech Input Using a Microphone and Translation of Speech to Text
Here is code that shows how to implement features and functions from the speech recognition module
import speech_recognition as srimport pyttsx3# Initialize the recognizerr = sr.Recognizer()# Function to convert text to speechdef SpeakText(command): # Initialize the engine engine = pyttsx3.init() engine.say(command) engine.runAndWait()# Loop infinitely for the user to speakwhile True: # Exception handling to handle # exceptions at the runtime try: # use the microphone as the source for input. with sr.Microphone() as source: # wait for a second to let the recognizer # adjust the energy threshold based on # the surrounding noise level r.adjust_for_ambient_noise(source, duration=0.2) #listens for the user's input audio = r.listen(source) # Using ggogle to recognize audio user_input = r.recognize_google(audio) user_input = user_input.lower() print("User: "+user_input) SpeakText(user_input) except Exception as e: print(e)
So yeah that was here I wanna wrap things here make sure to comment if you have any queries regarding this blog see ya <3
Original Link: https://dev.to/preetsuthar/python-text-to-speech-converter-30c2
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To