Skip to content

Instantly share code, notes, and snippets.

@kumarldh
Created September 29, 2026 05:27
Show Gist options
  • Select an option

  • Save kumarldh/a3c68cead1172a08ce0baf4c19c71c3e to your computer and use it in GitHub Desktop.

Select an option

Save kumarldh/a3c68cead1172a08ce0baf4c19c71c3e to your computer and use it in GitHub Desktop.
faster whisper
# # faster-whisper
# Use faster-whisper to transcribe an audio file.
#
# Set up
#
# ```
# $ python3 -m venv venv
# $ source venv/bin/activate
# $ pip3 install -r requirements.txt
# ```
#
# [Hugging Face CLI](https://huggingface.co/docs/huggingface_hub/en/guides/cli) would be required as well.
#
# Once HF CLI is setup download the model, example
#
# ```
# $ hf download Systran/faster-whisper-large-v3 --local-dir ./faster-whisper-large-v3
# ```
#
#
# Run within venv environment
#
# ```
# $ python run.py --input /path/to/input/wave/file.wav
# ```
#
# Run from outside venv environment
#
# ```
# $ /path/to/faster-whisper/venv/bin/python3 run.py --input /path/to/input/wave/file.wav
# ```
import os
import argparse
from pathlib import Path
import sys
from faster_whisper import WhisperModel
model_size = "large-v3"
local_model_path = Path(__file__).resolve().parent / "faster-whisper-large-v3"
local_model_path_str = str(local_model_path)
# Run on GPU with FP16
# model = WhisperModel(model_size, device="cuda", compute_type="float16")
# or run on GPU with INT8
# model = WhisperModel(model_size, device="cuda", compute_type="int8_float16")
# or run on CPU with INT8
model = WhisperModel(local_model_path_str, device="cpu", compute_type="int8", local_files_only=True )
parser = argparse.ArgumentParser(description="A script to process segments.")
parser.add_argument("--input", type=str, help="Input file")
args = parser.parse_args()
if args.input is None:
print("❌ Error: You forgot to provide the --input argument.")
print("Usage: python run.py --input <filename>")
sys.exit(1) # Exits the script with an error code
segments, _ = model.transcribe(args.input, beam_size=5)
segments = list(segments) # The transcription will actually run here.
transcribedText = "".join(str(s.text) for s in segments)
original_path = Path(args.input)
# Extract filename and insert the 'stt' subfolder
new_dir = original_path.parent / "stt"
new_filename = original_path.name.replace(".wav", ".txt")
# Combine into the final path
new_path = new_dir / new_filename
# Convert back to a string
new_path_str = str(new_path)
#file_name = f"{args.input}.txt"
with open(new_path_str, "w") as f:
f.write(transcribedText)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment