Estimate Your Presentation

 

This is a simple Python snippet to calculate your voice time based on TTS techinique.

Prerequisites:

pip install gTTS mutagen

Procedure

Firstly, load necessary packages

from gtts import gTTS
from mutagen.mp3 import MP3

Input a piece of words:

content = '''
Drag and drop your files, or type, paste, and edit text here.
Natural Reader is a professional text to speech program that converts any written text into spoken words. The paid versions of Natural Reader have many more features.
If you are interested in using our voices for non-personal use such as for Youtube videos, e-Learning, or other commercial or public purposes, please check out our Natural Reader Commercial web application.
'''

In the following we would use gTTS() function:

Parameters of gTTS()

  • text: what you want to say
  • lang: what kind of language. en for English, jp for Japanese, cn for Chinese
  • tld: translation domain. Depending on where you are living, you may access https://translate.google.cn rather than default https://translate.google.com. So please set up with cn, otherwise ignore it. See more details here https://gtts.readthedocs.io/en/latest/module.html

Use gTTS() to convert text to voice:

tts = gTTS(text=content, lang='en', tld='cn')
mp3_path = 'tmp.mp3'
tts.save(mp3_path)

In order to see this in Jupyter Notebook, you can try

from IPython.core.display import display, HTML
display(HTML("<audio controls><source src={} type='audio/mpeg'></audio>".format(mp3_path)))

Finally, we output the estimated time:

audio = MP3(mp3_path)
print(f"Estimated speaking time: {audio.info.length} seconds")