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.26.tar.gz (15.2 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.26-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: articast-0.1.26.tar.gz
  • Upload date:
  • Size: 15.2 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.26.tar.gz
Algorithm Hash digest
SHA256 1c03179078297f6540384fa1f45f7a73d09e38d22b75a8773f0d81e31a8d8f31
MD5 5c3e0e53a43546350e503f2a0fdae111
BLAKE2b-256 a1af76a03a2aa97f367056c2b20bc5ab91c5e084a4e94e553fc4b2df66e572ad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: articast-0.1.26-py3-none-any.whl
  • Upload date:
  • Size: 14.7 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.26-py3-none-any.whl
Algorithm Hash digest
SHA256 90f11b86ad19bc57a823d5e3317a8739e96858b83fa23f81b34192b3eb2c96a6
MD5 82513a65590b6dc4ecf1cee3b38842fe
BLAKE2b-256 ca5525d68029784376115014f3bfadb20bf514e82e9a6b3394e776fa1ecad1dd

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