Select Page

We use python module gTTS to convert any text to speech. This module uses Google text to speech engine to convert text to an mp3 file. Then we play the saved mp3 using the omxplayer.

Installing gTTS

This step is required only once. Go to the linux terminal window and type the following commands.

$sudo pip3 install -U requests
$sudo pip3 install gTTS

Python Code

from gtts import gTTS
import os
import time
t1='Hello! I am OK PI. I am here to help you.'
#t1=input("Enter a text to be spoken: ")
tts = gTTS(text=t1, lang='en')'hellot2s.mp3')
os.system("omxplayer hellot2s.mp3")
print('Good bye')