Skip to main content

Text to Speech (TTS) Project

This project leverages pyttsx3 for microsoft's built-in text-to-speech feature. It's designed for simplicity and ease of use, allowing you to configure continuous text-to-speech functionality and optional English translation.

Features

  • Continuous Text-to-Speech: Decide if you want the text-to-speech functionality to run continuously.
  • Optional English Translation: Choose whether to translate text to English before speaking.
  • Easy Configuration: Simple setup using two text files.

Prerequisites

  • pyttsx3

Setup

  1. Install dependencies:

    pip install pyttsx3
    
  2. Create Configuration Files:

    • input_sentence_file.txt: This file will contain the sentences that need to be spoken.
    • stop_or_not_file.txt: This file will control whether the text-to-speech function continues to check the input text file for new sentences. It should contain either "A" or "B".
      • "A" means the function will continue to work.
      • "B" means the function will stop.

Usage

To use the text-to-speech functionality, import the Speaker class from python-text-to-speech and initialize it with the appropriate parameters.

from python-text-to-speech import Speaker

ai = Speaker(
    input_file_path="input_sentence_file.txt",
    stop_file_path="stop_or_not_file.txt",
    log_file="TTS.log"
    translate=True | False,
    speak_continous=True | False
)

ai.add_more_voice("/temporary_directory_for_working", "voice_install_log_file.log") # Initialize all the voices avaliable in system

voices_list = ai.populate_voices() # to get list of available voices in your system

ai.set_voice(voice_name) # voice name should be the exact name of voice provided in vlices_list

ai.speak() # to speak sentences

Parameters

  • input_file_path (str): Path to the file containing sentences to be spoken.
  • stop_file_path (str): Path to the file that controls whether to stop or continue.
  • log_file (str): Path to a log file where all the logs will be stored.
  • translate (bool): Set to True to translate the text to English before speaking, False otherwise.
  • speak_continous (bool): Set to True for continuous text-to-speech, False for single execution.

Continuous Usage

If you want the text-to-speech functionality to run continuously, it is recommended to use threading. This will prevent the function from blocking the execution of further code until it is stopped.

Example with Threading

import threading
from python-text-to-speech import Speaker

def tts_thread():
    ai = Speaker(
        input_file_path="input_sentence_file.txt",
        stop_file_path="stop_or_not_file.txt",
        translate=True,
        speak_continous=True
    )
    ai.speak()

# Start TTS in a separate thread
thread = threading.Thread(target=tts_thread)
thread.start()
thread.join()

To make the program speak, update the sentence in input_sentence_file.txt. To stop the function, change the value in stop_or_not_file.txt from "A" to "B".

How to add more voices

  • Open windows setting and navigate to Time & language => Speech => Add voices and download the language whose voice you need to use.
  • Wait for 5 minutes the restart your device.
  • import System_Voices_Manager from python-text-to-speech.Register and follow the code
from python-text-to-speech.Register import System_Voices_Manager
import os

if __name__ == "__main__":
    sys = System_Voices_Manager("voice_install_log_file.log")
    sys.install_all_voices(os.path.join(os.getcwd(), "export"))
  • Now all voices are ready to use. You can populate the voice and set it to engine. Read the usage to know how to set voice.

This project is managed by Artex AI. Soon an improved and stable version will roll out

Metadata

Release files for python-text-to-speech 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-text-to-speech 0.0.2
File Size Uploaded
python_text_to_speech-0.0.2.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-text-to-speech 0.0.2
File Interpreter ABI Platform
python_text_to_speech-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / python_text_to_speech-0.0.2.tar.gz

Download URL python_text_to_speech-0.0.2.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e458fe9fa93d5f4fe34c9934da85543717eeee1a97432b9d07ce861f71016da2
BLAKE2b-256 checksum
How to use checksums
9700234af44e821cddefa4b19dcabea6bd3988df1ccb32c06e7de42d011bc11d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release files / python_text_to_speech-0.0.2-py3-none-any.whl

Download URL python_text_to_speech-0.0.2-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9cae31f78813c05da960e1aa1257569747d488c734c0aace6d3c9eb1c719175f
BLAKE2b-256 checksum
How to use checksums
1412e1b058a0aa3bbc68cf1c3017845f07b465faad721546b83ac2907000e6fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.13.0

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page