Skip to main content

A Python package for converting PDF and TXT files to audio

Project description

Text To Speech

The TextToSpeech project is a Python-based application that enables users to convert PDF and TXT files into audio files in the WAV format. With this project, users can easily transform written text into spoken words, making it convenient for individuals who prefer listening over reading. The project utilizes the PyPDF2 library to extract text from PDF files and supports direct text input from TXT files. Users can specify the desired language and pass the text to a Text-to-Speech API, which generates the corresponding audio data. The final output is saved as an audio file in WAV format, providing a seamless experience for anyone looking to convert written content into an audio format.

Installation

You can install TicTacToeEnhanced using pip:

pip install pdftext-to-speech

Usage

from textToSpeech.textToSpeech import Audio, AudioRequest, File

# you can use any other API, I am using text to speech from rapidapi
url = "https://text-to-speech27.p.rapidapi.com/speech"

# define your filename and working directory
# define working directory (the directory where the file resides). Keep empty to get the file from the same working directory
my_file = File('sample.pdf', working_dir='speeches')

# text response is a dict with the text inside txt
text = my_file.read_file()["txt"]

# make sure to define your language
# for a full list check languages.txt in the git repo
querystring = {"text":text,"lang":"en-us"}

# particular for this API. Use your own
headers = {
	"X-RapidAPI-Key": "YOUR API KEY",
	"X-RapidAPI-Host": "text-to-speech27.p.rapidapi.com"
}

audio_request = AudioRequest(url=url, querystring=querystring, headers=headers)
response = audio_request.request_audio_data()

# name your file what you want, my api return bytes convertable to wav
# you can change your output directory or keep it empty so the file is saved same as your working directory
audio = Audio(audio_filename="speech.wav", output_directory="speeches")

result = audio.save_audio_file(response)

print(result["message"])

Enjoy :)

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License

You can now copy this code and use it as your README.md file.

Project details


Release history Release notifications | RSS feed

This version

1.1

Download files

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

Source Distribution

pdftext-to-speech-1.1.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file pdftext-to-speech-1.1.tar.gz.

File metadata

  • Download URL: pdftext-to-speech-1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for pdftext-to-speech-1.1.tar.gz
Algorithm Hash digest
SHA256 d55f3acd6e6a7ebde3e3e51f306a61541d487a9d0cd31515546ac7c0665c8bba
MD5 ada311bd265afa50d20107d31434a2a6
BLAKE2b-256 0dddb46c677a1d4c9a8ff2bd955a69bd968e6388397b462621d262a0232fd09d

See more details on using hashes here.

Provenance

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