Skip to main content

CLI to transcript and translate audio and video files

Project description

Pytranscript 🎙️

Pytranscript is a powerful Python library and command-line tool designed to seamlessly convert video or audio files into text and translate them into various languages. It acts as a simple yet effective wrapper around Vosk, ffmpeg, and deep-translator, making the transcription and translation process straightforward.

Prerequisites

Before using pytranscript, ensure you have the following dependencies installed:

  • ffmpeg for audio conversion.
  • vosk-models required for speech recognition. You will have to specify to your specific model path in the --model argument.

Installation

pip install pytranscript

Usage

Command Line

pytranscript INPUT_FILE [OPTIONS]

Options

  • -m, --model - Path to the Vosk model directory. Always required.
  • -o, --output - Output file where the text will be saved. Default: input file name with .txt extension.
  • -li, --lang_input - Language of the input / the model. Default: auto.
  • -lo --lang_input - Language to translate the text to. Default: no translation.
  • -s, --start - Start time of the audio to transcribe in seconds.
  • -e, --end - End time of the audio to transcribe in seconds.
  • --max_size - Will stop the transcription if the output file reaches the specified size in bytes. Takes precedence over the --end option.
  • --keep-wav - Keep the converted audio wav file after the process is done.
  • -v, -verbosity - Verbosity level. 0: no output, 1: only errors, 2: errors, info and progressbar, 3: debug. Default: 2.

Example

The most basic usage is:

pytranscript video.mp4 -m vosk-model-en-us-aspire-0.2 -lo fr

Where vosk-model-en-us-aspire-0.2 is the Vosk model directory. The text will be translated from English to French, and the output will be saved in a file named video.txt.

Using the keep-wav option can be useful if you want to do many transcriptions within the same file, allowing you to use the same .wav file for each transcription, thus saving conversion time. ⚠️ The .wav file is cropped according to the start and end time options.

API

The API provides a Transcript object containing the time and text. The translate method can be used to get another Transcript object with the translated text. The output saved in a file in the cli is just the string str(transcript).

A reproduction of the previous example using the API:

import pytranscript as pt

wav_file = pt.to_valid_wav('video.mp4', "video.wav", start=0, end=None)
transcript = pt.transcribe(wav_file, model='vosk-model-en-us-aspire-0.2', max_size=None)
transcript_fr = transcript.translate('fr')

with open('video.txt', 'w', encoding="utf8") as f:
    f.write(str(transcript_fr))

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

pytranscript-0.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

pytranscript-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file pytranscript-0.1.0.tar.gz.

File metadata

  • Download URL: pytranscript-0.1.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for pytranscript-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2051c2790dd35b33868ea96e06383a8c9537dd84454cd3fb70a6c3a5d1b13930
MD5 8ad6c8d6291367ddc785b001c0eabf39
BLAKE2b-256 9a7dfa58bbce91f53cf5b7921ae6b2c1a682390cf4f134e0d16550b12eac6105

See more details on using hashes here.

File details

Details for the file pytranscript-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytranscript-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 628acc9c3fdde23221ed2077f276a0713f1cfbdfcc47f0a33476d8ed4f176edf
MD5 18d8a528facb46d9f9b888ba4d4709bb
BLAKE2b-256 ef40c26cc4102bfa3bda76a3464b5220c20646557a9e6983e3bfcc8a1fe11714

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page