nomadkaraoke / python-lyrics-transcriber

Automatically create synchronised lyrics files in ASS and MidiCo LRC formats with word-level timestamps, using Whisper and lyrics from Genius and Spotify, using LLMs / GPT-4 to correct transcribed lyrics
MIT License
32 stars 8 forks source link

Lyrics Transcriber 🎢

PyPI version

Automatically create synchronised lyrics files in ASS and MidiCo LRC formats with word-level timestamps, using OpenAI Whisper and lyrics from Genius and Spotify, for convenience in use cases such as karaoke video production.

Features 🌟

Installation πŸ› οΈ

Prerequisites

pip install lyrics-transcriber

Warning The package published to PyPI was created by manually editing poetry.lock to remove triton, as it is technically a sub-dependency from openai-whisper but is currently only supported on Linux (whisper still works fine without it, and I want this package to be usable on any platform)

Docker

You can use the pre-built container image beveradb/lyrics-transcriber:0.16.0 on Docker hub if you want, here's an example:

docker run \
 -v `pwd`/input:/input \
 -v `pwd`/output:/output \
beveradb/lyrics-transcriber:0.16.0 \
 --log_level debug \
 --output_dir /output \
 --render_video \
 --video_background_image /input/your-background-image.png \
 --video_resolution 360p \
 /input/song.flac

Usage πŸš€

As a standalone CLI

  1. To transcribe lyrics from an audio file:
lyrics-transcriber /path/to/your/audiofile.mp3
  1. To specify Genius API token, song artist, and song title for auto-correction:
lyrics-transcriber /path/to/your/audiofile.mp3 --genius_api_token YOUR_API_TOKEN --artist "Artist Name" --title "Song Title"

As a Python package in your project

  1. Import LyricsTranscriber in your Python script:
from lyrics_transcriber import LyricsTranscriber
  1. Create an instance and use it:
transcriber = LyricsTranscriber(audio_filepath='path_to_audio.mp3')
result_metadata = transcriber.generate()

result_metadata contains values as such:

result_metadata = {
    "whisper_json_filepath": str,
    "genius_lyrics": str,
    "genius_lyrics_filepath": str,
    "midico_lrc_filepath": str,
    "singing_percentage": int,
    "total_singing_duration": int,
    "song_duration": int,
}

Requirements πŸ“‹

Local Development πŸ’»

To work on the Lyrics Transcriber project locally, you need Python 3.9 or higher. It's recommended to create a virtual environment using poetry.

  1. Clone the repo and cd into it.
  2. Install poetry if you haven’t already.
  3. Run poetry install to install the dependencies.
  4. Run poetry shell to activate the virtual environment.

Contributing 🀝

Contributions are very much welcome! Please fork the repository and submit a pull request with your changes, and I'll try to review, merge and publish promptly!

License πŸ“„

This project is licensed under the MIT License.

Credits πŸ™

Contact πŸ’Œ

For questions or feedback, please raise an issue or reach out to @beveradb (Andrew Beveridge) directly.