Skip to main content

Create an mp3 file from spoken text via the Google TTS (Text-to-Speech) API

Project description

gTTS (Google Text to Speech): a Python interface to Google’s Text to Speech API. Create an mp3 file with the gTTS module or gtts-cli command line utility. It allows for unlimited lengths of spoken text by tokenizing long sentences where the speech would naturally pause.

[![Build Status](https://travis-ci.org/pndurette/gTTS.svg?branch=master)](https://travis-ci.org/pndurette/gTTS)

Install

pip install gTTS

Module

Instanciate:

>> from gtts import gTTS >> tts = gTTS(text=’Hello’, lang=’en’) >> tts.save(“hello.mp3”)

Parameters:

  • text is the text to speak to file;

  • lang is the language to speak in. A ISO 639-1 language code supported by the Google Text to Speech API.

Using a file-like object (Ex.):

>> from gtts import gTTS >> from tempfile import TemporaryFile >> tts = gTTS(text=’Hello’, lang=’en’) >> f = TemporaryFile() >> tts.write_to_fp(f) >> f.close()

Command line utility

Invoke gtts-cli:

gtts-cli.py –help usage: gtts-cli.py [-h] (-t TEXT | -f FILE) [-l LANG] [–debug] destination

(Ex.) Read the string ‘Hello’ in English to hello.mp3

$ gtts-cli.py -t “Hello” -l ‘en’ hello.mp3

(Ex.) Read the contents of file ‘hello.txt’ in Czech to hello.mp3:

$ gtts-cli.py -f hello.txt -l ‘cs’ hello.mp3

Supported Languages

  • ‘af’ : ‘Afrikaans’

  • ‘sq’ : ‘Albanian’

  • ‘ar’ : ‘Arabic’

  • ‘hy’ : ‘Armenian’

  • ‘ca’ : ‘Catalan’

  • ‘zh’ : ‘Chinese’,

  • ‘zh-cn’ : ‘Chinese (Mandarin/China)’

  • ‘zh-tw’ : ‘Chinese (Mandarin/Taiwan)’

  • ‘zh-yue’ : ‘Chinese (Cantonese)’

  • ‘hr’ : ‘Croatian’

  • ‘cs’ : ‘Czech’

  • ‘da’ : ‘Danish’

  • ‘nl’ : ‘Dutch’

  • ‘en’ : ‘English’

  • ‘en-au’ : ‘English (Australia)’

  • ‘en-uk’ : ‘English (United Kingdom)’

  • ‘en-us’ : ‘English (United States)’

  • ‘eo’ : ‘Esperanto’

  • ‘fi’ : ‘Finnish’

  • ‘fr’ : ‘French’

  • ‘de’ : ‘German’

  • ‘el’ : ‘Greek’

  • ‘ht’ : ‘Haitian Creole’

  • ‘hi’ : ‘Hindi’

  • ‘hu’ : ‘Hungarian’

  • ‘is’ : ‘Icelandic’

  • ‘id’ : ‘Indonesian’

  • ‘it’ : ‘Italian’

  • ‘ja’ : ‘Japanese’

  • ‘ko’ : ‘Korean’

  • ‘la’ : ‘Latin’

  • ‘lv’ : ‘Latvian’

  • ‘mk’ : ‘Macedonian’

  • ‘no’ : ‘Norwegian’

  • ‘pl’ : ‘Polish’

  • ‘pt’ : ‘Portuguese’

  • ‘pt-br’ : ‘Portuguese (Brazil)’

  • ‘ro’ : ‘Romanian’

  • ‘ru’ : ‘Russian’

  • ‘sr’ : ‘Serbian’

  • ‘sk’ : ‘Slovak’

  • ‘es’ : ‘Spanish’

  • ‘es-es’ : ‘Spanish (Spain)’

  • ‘es-us’ : ‘Spanish (United States)’

  • ‘sw’ : ‘Swahili’

  • ‘sv’ : ‘Swedish’

  • ‘ta’ : ‘Tamil’

  • ‘th’ : ‘Thai’

  • ‘tr’ : ‘Turkish’

  • ‘vi’ : ‘Vietnamese’

  • ‘cy’ : ‘Welsh’

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gTTS-1.0.6.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file gTTS-1.0.6.tar.gz.

File metadata

  • Download URL: gTTS-1.0.6.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for gTTS-1.0.6.tar.gz
Algorithm Hash digest
SHA256 c6e890415f94f7307beaa4a5a7e9ea31cd5069706e1636f49cf73e71b3422563
MD5 25d736b90db5b1668eac82216fe029f6
BLAKE2b-256 8cc2c5f7a2c2b99b8bb858b7e0eb642737b1060b7bd5f8d115824c0c5757886c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page