Skip to main content

GPT-4 based informational audiobook/podcast mp3 generator

Project description

podgenai

podgenai is a Python 3.12 application to generate an informational single-speaker audiobook/podcast mp3 file on a given topic using the GPT-4 LLM. The loosely targeted duration of the generated file is an hour, although the generated duration varies. A funded OpenAI API key is required.

Links

Caption Link
Repo https://github.com/impredicative/podgenai
Changelog https://github.com/impredicative/podgenai/releases
Package https://pypi.org/project/podgenai
Podcast https://podcasters.spotify.com/pod/podgenai
Podcast RSS https://anchor.fm/s/f4868644/podcast/rss

Approach

The gpt-4o and tts-1 models are used. For a given topic, the high-level reference approach is:

  • Applicable subtopics are listed using the LLM. If however the topic is unknown to the LLM, the process is aborted.
  • The voice is selected using the LLM from four choices.
  • Concurrently for each subtopic, the corresponding text and speech are generated using the LLM and TTS respectively.
  • The speech files are concatenated using ffmpeg.

Although there may sometimes exist some semantic repetition of content across subtopics, this has intentionally not been "optimized away" because this repetition of important points can help with learning and memorization. To dive deeper into a particular subtopic, one can try to create a new file just for it.

Samples

These generated mp3 files are available for download, one for each voice. As a reminder, the voice is selected by the LLM.

There is also a related podcast (RSS) to which episodes on additional topics may be manually posted over time.

A playback speed of 1.05x is recommended for non-technical topics, 1.0x for technical topics, and 0.95x for foreign language topics.

Voice Name
analytical-male Artificial General Intelligence (AGI): Approaches and Algorithms
elegant-female Monero
expository-male History of Neural Networks
motivating-male Living a good life
serene-female Human circulatory system (unabridged)
stoic-male Bitcoin for nerds

Setup

Common setup

  • In the working directory, create a file named .env, with the intended environment variable OPENAI_API_KEY=<your OpenAI API key>, or set it in a different way.
  • Optionally also set the environment variable PODGENAI_OPENAI_MAX_WORKERS=32 for faster generation, with its default value being 16.
  • Ensure that ffmpeg is available. This is automatic if using the included devcontainer definition.
  • Continue the setup via GitHub or PyPI as below.

Setup via GitHub using devcontainer

  • Continue from the common setup steps.
  • Clone or download this repo.
  • Build and provision the defined devcontainer.

Setup via GitHub manually

  • Continue from the common setup steps.
  • Clone or download this repo.
  • Ensure that rye is installed and available.
  • In the repo directory, run rye sync --no-lock.

Setup via PyPI

  • Continue from the common setup steps.
  • Create and activate a Python 3.12 devcontainer or virtual environment.
  • Install via PyPI: pip install -U podgenai.

Usage

Usage can be as a command-line application or as a Python library. By default, the generated mp3 file will be written to the current working directory. As of 2024, the typical cost per generation is 1 to 3 USD, more specifically under 0.10 USD per subtopic. The time taken is under three minutes.

Usage tips

  • If a requested topic fails to generate subtopics due to a refusal, retry up to a few times, as it may succeed with several attempts. If it doesn't, try rewording it, perhaps to be broader or narrower or more factual. Up to two attempts are made per run, although the first attempt will reuse the disk cache if available.
  • For a potentially longer list of covered subtopics, consider appending the "(unabridged)" suffix to the requested topic, e.g. "PyTorch (unabridged)".
  • In case the topic fails to be spoken at the start of a podcast, delete ./work/<topic>/1.*.mp3 and regenerate the output.
  • To optionally generate a cover art image for your topic, this custom GPT can be used.
  • To attempt generation in a foreign language, specify the title in the desired language along with a parenthesized prefix of the language name, e.g. "México (español)". If the generation is refused the first time, try again. Also refer to and use the --no-markers option.

Usage as application

Usage help is copied below:

$ python -m podgenai -h
Usage: python -m podgenai [OPTIONS]

  Generate and write an audiobook podcast mp3 file for the given topic to the given output file path.

Options:
  -t, --topic TEXT                Topic. If not given, the user is prompted for it.
  -p, --path PATH                 Output file or directory path. If an intended file path, it must have an ".mp3"
                                  suffix. If a directory, it must exist, and the file name is auto-determined. If not
                                  given, the output file is written to the current working directory with an auto-
                                  determined file name.
  -s, --max-sections INTEGER RANGE
                                  Maximum number of sections, between 3 and 100. If not given, it is unrestricted.
                                  [3<=x<=100]
  -m, --markers / -nm, --no-markers
                                  Include markers at the start or end of sections in the generated audio. If
                                  `--markers`, markers are included, and this is the default. If `--no-markers`,
                                  markers are excluded, as can be appropriate for foreign-language generation.
  -c, --confirm / -nc, --no-confirm
                                  Confirm before full-text and speech generation. If `--confirm`, a confirmation is
                                  interactively sought as each step of the workflow progresses, and this is the
                                  default. If `--no-confirm`, the full-text and speech are generated without
                                  confirmations.
  -h, --help                      Show this message and exit.

Usage examples:

$ python -m podgenai -t "My favorite topic"

$ python -m podgenai -t "My favorite topic" -p ~/Downloads/

$ python -m podgenai -t "My favorite topic" -p ~/Downloads/topic.mp3 -nc

$ python -m podgenai -t "L'histoire de Napoléon Bonaparte (français)" -nm

Usage as library

>>> from podgenai import generate_media
>>> import inspect

>>> print(inspect.signature(generate_media))
(topic: str, *, output_path: Optional[pathlib.Path] = None, max_sections: Optional[int] = None, markers: bool = True, confirm: bool = False) -> pathlib.Path

>>> print(inspect.getdoc(generate_media))
Return the output path after generating and writing an audiobook podcast to file for the given topic.

Params:
* `topic`: Topic.
* `path`: Output file or directory path.
    If an intended file path, it must have an ".mp3" suffix. If a directory, it must exist, and the file name is auto-determined.
    If not given, the output file is written to the repo directory with an auto-determined file name.
* `max_sections`: Maximum number of sections to generate. It is between 3 and 100. It is unrestricted if not given.
* `markers`: Include markers at the start or end of sections in the generated audio.
    If true, markers are included. If false, markers are excluded, as can be appropriate for foreign-language generation. Its default is true.
* `confirm`: Confirm before full-text and speech generation.
    If true, a confirmation is interactively sought after generating and printing the list of subtopics, before generating the full-text, and also before generating the speech. Its default is false.

If failed, a subclass of the `podgenai.exceptions.Error` exception is raised.

Cache

Text and speech segments are cached locally on disk in the ./work/<topic> directory. They can manually be deleted. This deletion is currently not automatic. Moreover, it can currently be necessary to delete one or more applicable cached files if the cache is to be bypassed.

Disclaimer

This software is provided "as is," without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the software or the use or other dealings in the software.

Users should be aware that both the text and the audio of the generated files are produced by artificial intelligence (AI) based on the inputs given and the data available to the AI model at the time of generation. As such, inaccuracies, errors, or unintended content may occur. Users are advised to exercise caution and verify the accuracy and appropriateness of the generated content before any use or reliance.

You are responsible for the costs associated with the use of the OpenAI API as required by the software, and you must comply with the OpenAI API terms of service. The software's functionality is dependent on the availability and functionality of external services and software, including but not limited to the OpenAI API and ffmpeg, over which the authors have no control.

The use of the OpenAI API key and any generated content must comply with all applicable laws and regulations, including copyright laws and the terms of service of the OpenAI platform. You are solely responsible for ensuring that your use of the software and any generated content complies with the OpenAI terms of service and any other applicable laws and regulations.

This software is licensed under the GNU Lesser General Public License (LGPL), which allows for both private and commercial use, modification, and distribution, subject to the terms and conditions set forth in the LGPL. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.

The authors do not claim ownership of any content generated using this software. Responsibility for the use of any and all generated content rests with the user. Users should exercise caution and due diligence to ensure that generated content does not infringe on the rights of third parties.

This disclaimer is subject to change without notice. It is your responsibility to review it periodically for updates.

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

podgenai-0.13.0.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

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

podgenai-0.13.0-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file podgenai-0.13.0.tar.gz.

File metadata

  • Download URL: podgenai-0.13.0.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.8

File hashes

Hashes for podgenai-0.13.0.tar.gz
Algorithm Hash digest
SHA256 acc31a69eaa8a63a2cccb4d614fcb0d2958ba2175780180742d1f0e50b559f08
MD5 ff740cdda67b1811eec75c8cdd243b0f
BLAKE2b-256 7fa457b1a6422378e2b376bd4e5fe64b754f355ccf7e9a5b5b9e6beb6a92e5b6

See more details on using hashes here.

File details

Details for the file podgenai-0.13.0-py3-none-any.whl.

File metadata

  • Download URL: podgenai-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.8

File hashes

Hashes for podgenai-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa23f0480e1c3f4101839a7ea8c0f71f6cc3e15b4ec3b4688dadee9b43dce87e
MD5 808f59e0d316aa0220590251ea1db1e1
BLAKE2b-256 1aead886376c658d0576b921c8e3d3125ebd18c789a3433a59bdf1f97371901f

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