1hr_demo / align.py
tuklu's picture
Override with Parquet version
9422b57 verified
## this file need nvidia gpu, use google colab or your local with nvidia gpu
import stable_whisper
import whisper
import json
audio_path = "master.mp3"
transcript_path = "transcript.txt"
output_path = "aligned_transcription.json"
print("Loading 'medium' model via stable-whisper on GPU...")
model = stable_whisper.load_model('medium', device='cuda')
print(f"Loading transcript from: {transcript_path}")
with open(transcript_path, "r", encoding="utf-8") as f:
transcript_text = f.read()
print(f"Pre-loading audio from: {audio_path}")
audio_data = whisper.load_audio(audio_path)
print("Aligning audio and text on GPU with stable-whisper...")
result = model.align(audio_data, transcript_text, language='as')
print(f"Alignment complete. Saving results to {output_path}")
result_dict = result.to_dict()
with open(output_path, "w", encoding="utf-8") as f:
json.dump(result_dict, f, ensure_ascii=False, indent=2)
print("Process finished. You can download the JSON file from the sidebar.")