
Lear how to Create a Text to Speech Python script using Google Colaboratory
To create a Text to Speech Python script you can follow the steps below:
- Open Google Colaboratory:
- Go to Google Colaboratory and sign in with your Google account.
- Create a new Python notebook:
- Click on “File” -> “New Python 3 Notebook” to create a new notebook.
- Import required libraries:
- Import the required libraries for the Text to Speech conversion. For example, you can use the gTTS library to convert text to speech.
Add new Code Section with the command below and click play to install the gTTS library

Enter text to convert:
In the first cell of the notebook, enter the text that you want to convert to speech.
The full Python Script should looks like the code below
from gtts import gTTS
text = "Hello, how are you today?"
language = 'en'
tld = '.com' # English voice
speech_speed = 1 # normal speech speed
tts = gTTS(text=text, lang=language, slow=False)
# Save the speech as an audio file
filename = 'speech.mp3'
tts.save(filename)
# Play the speech
from IPython.display import Audio
Audio(filename)
The Script will display similar data and player with the mp3 record from your text

Lear how to Create a Text to Speech Python script using Google Colaboratory
- Run the script:
- Run the script by clicking on the “Run” button at the top of the notebook or by pressing “Shift + Enter” on your keyboard.
- Listen to the audio output:
- Once the script is executed, you will see a new audio file named “hello.mp3” in the Files tab on the left-hand side. You can listen to the audio output by clicking on the file.