Skip to main content

Create an audio program from a text file containing English sentences

Project description

apg (audio_program_generator)

Generates an audio program from text, with option to mix in background sound.

Possible use cases:

  • make your own yoga or qi gong routine
  • create an audio book
  • read a kid a bedtime story without actually having to do the reading

Prerequisites

  • Python (3.7+) [note to mac users: your system may be using Python 2.7 by default. To find out, issue the command python --version. If your system shows anything less than 3.7, make sure you create a virtual environment before installing this package (see Installation section below)]
  • Local installation of ffmpeg

Installation & Invocation

The easiest way to get started is to use pip to install apg as a package.

  1. (optional, but recommended) create a virtual environment to install the package into: python -m venv .venv source ./.venv/bin/activate
  2. Install the package: $ pip install audio-program-generator Once this is done, you will have an "apg" executable available in your terminal. You can type apg for basic help, or apg --help for full instructions.

An alternative is to build and install the package from source (requires git and poetry): git clone https://github.com/jeffwright13/audio_program_generator.git cd audio_program_generator poetry install poetry shell apg Once this is done, you will have an "apg" executable available in your terminal. You can type apg for basic help, or apg --help for full instructions.

Finally, there is a sister project that wraps the apg module in a bare-bones Flask app. This can be hosted locally, or in a cloud provider such as Heroku, Digital Ocean, or AWS. This method is considered experimental at the moment, and is not officially supported.

Usage

Assumes you are using the provided apg command line interface.

  1. Populate a semicolon-separated text file with plain-text phrases, each followed by an inter-phrase duration. Each line of the file is comprised of:
    • one phrase to be spoken
    • a semicolon
    • a silence duration (specified in seconds)
  2. Provide a sound file for background sound (optional).
  3. Execute the command in your terminal: apg <phrase_file> [sound_file].

The script will generate and save a single MP3 file. The base name of the MP3 file is the same as the specified input file. For example, if the script is given input file "phrases.txt", the output file will be "phrases.mp3". It will be saved to the same folder that the input text file was taken from.

The optional [sound_file] parameter, when specified, is used to mix in background sounds/music. This parameter specifies the path/filename of the sound file to be mixed in with the speech generated from the phrase file. If the sound file is shorter in duration than the generated speech file, it will be looped. If it is longer, it will be truncated. The resulting background sound (looped or not) will be faded in and out to ensure a smooth transition (6 seconds at beginning and en). Currently, only .wav files are supported as inputs.

The --attenuation option allows fine-tuning the background sound level so it doesn't drown out the generated speech.

The --slow option generates each speech snippet is a slow-spoken style.

The CLI prints out a progress bar as the phrase file is converted into speech snippets. No progress bar is shown for the secondary mix step. There may be a significant delay in going from the end of the first stage (snippet generation) to the end of the second stage (mixing), primarily because of reading in the .wav file, which may be large. For this reason, you may want to select a sound file for mixing that is small (suggested <20MB). Otherwise, be prepared to wait.

Options

There are several options available on the command line to customize your generated program file.

-a  --attenuation  dB attenuation applied to
                   background file when mixing
-s  --slow         Generate slow speech snippets
-h  --help         Print out help
-V  --version      Print out apg version

Example <phrase_file> format:

Phrase One;2
Phrase Two;5
Phrase Three;0

Author:

Jeff Wright jeff.washcloth@gmail.com

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

audio_program_generator-1.6.3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

audio_program_generator-1.6.3-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file audio_program_generator-1.6.3.tar.gz.

File metadata

  • Download URL: audio_program_generator-1.6.3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.1 Darwin/19.6.0

File hashes

Hashes for audio_program_generator-1.6.3.tar.gz
Algorithm Hash digest
SHA256 ce81ebe486bd419febc186adab6e5e951244d9ea84a5d0ada3918b9a0babe0d4
MD5 7b52311adc3324fc60ab33dba1742d62
BLAKE2b-256 51d9a8615b36c396ffcb0b077ad2969c6193fc0c17d0b759887d83972ad041fe

See more details on using hashes here.

File details

Details for the file audio_program_generator-1.6.3-py3-none-any.whl.

File metadata

File hashes

Hashes for audio_program_generator-1.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ba407a493f24dc23754cdf9f6b0d858351b476d0fe1b30855cf917f7a4886ac6
MD5 94eca0ef3f8de1981e15975559784075
BLAKE2b-256 be7b7ddbed1f975a2e469beb06e06668394f573a575386daaa7d9bfcd9c52c27

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