Skip to main content

Simplifies arranging text fragments with multiple speakers and processing it with coqui.ai TTS

Project description

TTS Arranger

Library that simplifies arranging text items fragments with multiple speakers and processing them using coqui.ai TTS to write audio files. It also features helper classes for converting HTML (and thus EPUB files) into TTS projects, based of customizeable rules to read specific elements with different speakers, and define pauses after certain elements.

Overview

TTS project elements

  • TTS_Item, TTS_Chapter, TTS_Project

Writer Classes

  • TTS_Simple_Writer: Simple single-file writer, works with lists of TTS_Items directly
  • TTS_Writer: Designed for writing audiobooks with meta data and chapters, works on with TTS_Project

Reader Classes

  • TTS_Text_Reader: Reads and converts plain text into a TTS_Project instance
  • TTS_HTML_Reader: Reads and converts HTML content into a TTS_Project instance
  • TTS_EPUB_Reader: Reads and converts an EPUB file into a TTS_Project instance
  • TTS_SRT_Reader: Reads and converts an SRT subtitle file into a TTS_Project instance [not working due to timing bug at this point]

Helper Classes

  • TTS_Processor: Takes a TTS_Item, synthesizes and writes it to a file, also takes care of preprocessing the text input and post processing the audio output
  • TTS_HTML_Converter: Parses HTML content into a TTS_Project (mainly used by TTS_HTML_Reader and TTS_EPUB_Reader)

Requirements

  • ffmpeg, espeak-ng
  • for required Python packages see requirements.txt

Examples

import os

from tts_arranger import TTS_Item, TTS_Simple_Writer

# Simple example using Simple Writer (using a simple list of TTS items), uses tts_models/en/vctk/vits by (default)

user_dir = os.path.expanduser('~')

tts_items = []

preferred_speakers = ['p273', 'p330']

tts_items.append(TTS_Item('This is a test', 0))  # Uses preferred speaker #0
tts_items.append(TTS_Item(length=2000))  # Insert pause
tts_items.append(TTS_Item('This is a test with another speaker and a fixed minimum length', 1, length=10000)) # Uses preferred speaker #1 and sets minimum length

# Create writer using our item list and prefered speakers and synthesize and save as mp3 audio
simple_writer = TTS_Simple_Writer(tts_items, preferred_speakers)
simple_writer.synthesize_and_write(os.path.join(user_dir, 'tts_arranger_example_output/test.mp3'))

# English example using tts_models/en/vctk/vits (with multispeaker support)

items1 = []
items1.append(TTS_Item('This is a test:', 0))
items1.append(TTS_Item('This is another test:', 1))

items2 = []
items2.append(TTS_Item('Another test',  0))
items2.append(TTS_Item('This is getting boring!', 1))

chapter = []
chapter.append(TTS_Chapter(items1, 'Chapter 1'))
chapter.append(TTS_Chapter(items2, 'Chapter 2'))

project = TTS_Project(chapter, 'Project Title', 'Project Subtitle', author='Some Author')

# Add a cover image
project.add_image_from_url('https://coqui.ai/static/38a06ec53309f617be3eb3b8b9367abf/598c3/logo-wordmark.png')

writer = TTS_Writer(project, os.path.join(user_dir, 'tts_arranger_example_output/'), preferred_speakers=preferred_speakers)
writer.synthesize_and_write(project.author + ' - ' + project.title)

# German example using Thorsten voice (no multispeaker support)

items1 = []
items1.append(TTS_Item('Dies ist ein Test:', speaker_idx=0))
items1.append(TTS_Item('Noch ein Test:',  speaker_idx=1))

items2 = []
items2.append(TTS_Item('Ein weiterer Test',  speaker_idx=0))
items2.append(TTS_Item('Langsam wird es langweilig!',  speaker_idx=1))

chapter = []
chapter.append(TTS_Chapter(items1, 'Kapitel 1'))
chapter.append(TTS_Chapter(items2, 'Kapitel 2'))

project = TTS_Project(chapter, 'Projektname', 'Projekt-Untertitel', author='Ein Autor', lang_code='de')

writer = TTS_Writer(project, os.path.join(user_dir, 'tts_arranger_example_output/'), model='tts_models/de/thorsten/tacotron2-DDC', vocoder='vocoder_models/de/thorsten/hifigan_v1', output_format='mp3')
writer.synthesize_and_write(project.author + ' - ' + project.title, concat=False)

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

tts_arranger-0.3.2b0.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

tts_arranger-0.3.2b0-py3-none-any.whl (36.6 kB view details)

Uploaded Python 3

File details

Details for the file tts_arranger-0.3.2b0.tar.gz.

File metadata

  • Download URL: tts_arranger-0.3.2b0.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for tts_arranger-0.3.2b0.tar.gz
Algorithm Hash digest
SHA256 0e543a99b11efb448d0dffb4138264aa3484aca81234b776caf3af540dd2cbcd
MD5 4bf0e63e089c6c134aae630e4234d3a8
BLAKE2b-256 8efbb747d8e4e2fcbd7520a0cff3ad411e4f749cd465573ffac52ac4aa776859

See more details on using hashes here.

File details

Details for the file tts_arranger-0.3.2b0-py3-none-any.whl.

File metadata

File hashes

Hashes for tts_arranger-0.3.2b0-py3-none-any.whl
Algorithm Hash digest
SHA256 739e6e6905d23af849708a75734a1b196214abbb70ac46ffb17a5dc017fced6c
MD5 5bf9a843b4434c7be842c150b479e025
BLAKE2b-256 54d7d4852aafb4dc80726a86b5f4390f2b38aecee1a0b774123580aaf850da08

See more details on using hashes here.

Supported by

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