Have you ever thought about how does Siri, Cortana, and Google Assistant able to reply to you with voice?. Well then stay tuned to this article.
speech synthesis
This can be achieved using Speech synthesis which is concerned with converting normal words into a human-like speech that we can understand.
Text to Speech Libraries
There some libraries in python that you can use to perform Speech synthesis in just few lines of code;
Text to Speech (TTS) using Pyttsx
pyttsx is a Python package supporting common text-to-speech engines on Mac OS X, Windows, and Linux.
Installation
#Linux pip3 install pyttsx #Window pip install pyttsx
Example of Usage of pyttsx
Create app.py then paste the below code and run it
import pyttsx as speech engine = speech.init() engine.say('Speech synthesis is process converting text to speech') engine.runAndWait()
TTS with Espeak
Espeak For those in Linux I would recommend using this library due to it’s easy installation and performance on Linux distro
Installation on Linux
sudo apt-get install espeak sudo apt-get installl python-espeak
Example of Usage (app.py)
from espeak import espeak as voice lang = 'en' #en is For English voice.set_voice(lang) voice.synth("I can speak"*5)
TTS with gTTS
gTTS (Google Text-to-Speech), a Python library and CLI tool to interface with Google Translate text-to-speech API
Installation
pip install gTTS
Example of Usage (app.py)
from gtts import gTTS tts = gTTS('Speech synthesis using Google speech engine ') tts.save('music.mp3')
TTS with Microsoft Speech Engine (SAPI)
Microsoft Speech Engine has a python wrapper to its Text to speech Engine which works only in Windows.
Installation
pip install pypiwin32
Example of Usage (app.py)
import win32com.client as mouth voice = mouth.Dispatch("SAPI.SpVoice") word_to_say = "Microsoft was founded by Bill gates " voice.Speak(word_to_say)
You have just learned how to convert to text speech, now can’t wait to see what you’re going to build with it.
I also recommend you to check these;
- How to translate languages using Python
- Emotion detection from the text in Python
- How to perform speech recognition in Python
- Make your own Plagiarism detector in Python
- Learn how to build your own spam filter in Python
- Make your own knowledge-based chatbot in Python
- How to perform automatic spelling correction in Python
- A quick guide to Twitter sentiment analysis using python
Subscribe to this blog to stay more updated on upcoming Python tutorials
In case of of any bug , comment, or suggestion leave it on the comment box
Awesome job man, yah go go Africa👍👍