Skip to main content

CLI tool for converting articles to podcasts

Project description

articast

PyPI Changelog Tests License

CLI tool for converting articles to podcasts using AI Text-to-Speech APIs. I have added ElevenLabs basic functionanlity, but it's very simple, and I still use OpenAI more for it's cheapness.

Requirements

You need to have ffmpeg installed before running this CLI tool.

brew install ffmpeg

Since JS based articles can't be rendered with requests we're using playwright and chromium web driver to tackle that:

pip install playwright
playwright install chromium

Usage

Install articast with:

pipx install articast
articast --help
Usage: python -m articast [OPTIONS]

Options:
  --url TEXT                      URL of the article to be fetched.
  --vendor [openai|elevenlabs]    Choose vendor to use to convert text to
                                  audio.
  --file-url-list FILE            Path to a file with URLs placed on every new
                                  line.
  --file-text FILE                Path to a file with text to be sent over to
                                  AI vendor. This is currently a workaround of
                                  Cloudflare blocking.
  --directory DIRECTORY           Directory where the output audio file will
                                  be saved. The filename will be derived from
                                  the article title.
  --speech-model TEXT             The model to be used for text-to-speech
                                  conversion.
  --text-model TEXT              The model to be used for text condensing
                                  (e.g., gpt-4-turbo-preview, gpt-3.5-turbo).
  --voice TEXT                    OpenIA voices: alloy, echo, fable, onyx,
                                  nova, shimmer; ElevenLabs voices: Sarah.
  --strip INTEGER RANGE           By what number of chars to strip the text to
                                  send to OpenAI.  [5<=x<=2000]
  --audio-format [mp3|opus|aac|flac|pcm]
                                  The audio format for the output file.
                                  Default is mp3.
  --condense                      Condense the article before converting to
                                  audio.
  --condense-ratio FLOAT RANGE    Ratio to condense the text (0.2 = 20% of
                                  original length).  [0.1<=x<=1.0]
  --help                          Show this message and exit.

OpenAI

export OPENAI_API_KEY="your-api-key"
articast \
    --url 'https://blog.kubetools.io/kopylot-an-ai-powered-kubernetes-assistant-for-devops-developers' \
    --speech-model tts-1-hd \
    --text-model gpt-4-turbo-preview \
    --voice nova \
    --condense \
    --condense-ratio 0.2 \
    --directory ~/Downloads/Podcasts

ElevenLabs:

export ELEVEN_API_KEY="your-api-key"
articast \
  --url 'https://incident.io/blog/psychological-safety-in-incident-management' \
  --vendor elevenlabs \
  --directory ~/Downloads/Podcasts

Development

If you're using Nix you can start running the tool by entering:

nix develop
export OPENAI_API_KEY="your-api-key"
python \
    -m articast \
    --speech-model tts-1-hd \
    --text-model gpt-4-turbo-preview \
    --voice nova \
    --directory . \
    --url 'https://blog.kubetools.io/kopylot-an-ai-powered-kubernetes-assistant-for-devops-developers' \
    --condense \
    --condense-ratio 0.2

Lint

I currently use these commands manually, maybe I will add some automation later on:

autoflake --in-place --remove-all-unused-imports --expand-star-imports -r .

Testing

If you used nix develop all necessary dependencies should have already been installed, so you can just run:

pytest

TODO

  • Fix issue when elevenlabs api key is not exposed to publish workflow:
    -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
    =========================== short test summary info ============================
    FAILED tests/test_main.py::test_process_article_elevenlabs - elevenlabs.core.api_error.ApiError: status_code: 401, body: {'detail': {'status': 'invalid_api_key', 'message': 'Invalid API key'}}
    =================== 1 failed, 5 passed, 1 warning in 24.14s ====================
    Error: Process completed with exit code 1.
    
  • Bypass Cloudflare block
  • Minimize costs on tests
  • Add ability to render images to text and send over to text to speech as well
  • Shorten filename created
  • Shorten article title printed to console
  • Send to device right away
  • Replace print with logger
  • Remove redundant warnings in pytest
  • Make sure pytest shows quota errors

Manual configurations

  • OPENAI_API_KEY secret was added to repository secrets
  • ELEVEN_API_KEY secret was added to repository secrets
  • PYPI_TOKEN was added to release environment secrets

Inspired by

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

articast-0.1.27.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

articast-0.1.27-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file articast-0.1.27.tar.gz.

File metadata

  • Download URL: articast-0.1.27.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for articast-0.1.27.tar.gz
Algorithm Hash digest
SHA256 e6892c9391349dddce63a40d02454a07aa2586813ffb2604c1b99198265fca69
MD5 dc43a340ace3f326c8bd8a8c388b7884
BLAKE2b-256 056187ae549cfacc9af45de34789e587c4d1ba1b2be60fbe83f496439d394b97

See more details on using hashes here.

File details

Details for the file articast-0.1.27-py3-none-any.whl.

File metadata

  • Download URL: articast-0.1.27-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for articast-0.1.27-py3-none-any.whl
Algorithm Hash digest
SHA256 75684146c8facc021aa53e9bccdb967a78857f06b37dc7170cbba8dd0c7022bf
MD5 2ced003eaae9e9f643af70666c49ef5c
BLAKE2b-256 70bd83f1b292049eba323f99e74b0703ec6200ee9e6c9a68d95047e0d596a6cd

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