Tag: transcription

  • Transcribe Audio for Free

    How to Transcribe Audio for Free Using Whisper on Kaggle (No Third-Party Uploads)

    If you make YouTube videos and need accurate subtitles, you don’t need to upload your audio to some random third-party website. In this tutorial, I’ll show you how I generate word-by-word, sentence-level, and karaoke-style subtitles completely for free, using a Kaggle notebook running OpenAI’s Whisper model — with everything staying under my control.

    Why This Approach?

    Privacy matters, especially if your audio contains anything sensitive or unfinished. Instead of sending your files to a third-party subtitle service, this method runs entirely inside your own Kaggle notebook. Your audio never leaves a platform you control.

    What You’ll Need

    • A free Kaggle account
    • An mp3, mp4, wav, or m4a audio file
    • Basic familiarity with running a Kaggle notebook

    Step 1: Upload Your Audio as a Kaggle Dataset

    Create a new dataset in Kaggle and upload your audio file to it. This keeps your file private and lets you swap it out later by simply bumping the dataset version.

    Step 2: Run the Transcription Script

    Here’s the full script. It uses stable-ts (built on top of OpenAI’s Whisper) to transcribe and align your audio, then exports three types of subtitle files.

    import os
    import glob
    os.system('pip install -q stable-ts')
    import stable_whisper
    
    WHISPER_MODEL = 'large'
    LANGUAGE      = 'en'
    OUTPUT_DIR    = '/kaggle/working'
    
    audio_files = (
        glob.glob('/kaggle/input/**/*.mp3', recursive=True) +
        glob.glob('/kaggle/input/**/*.mp4', recursive=True) +
        glob.glob('/kaggle/input/**/*.wav', recursive=True) +
        glob.glob('/kaggle/input/**/*.m4a', recursive=True)
    )
    if not audio_files:
        raise FileNotFoundError('No audio found in /kaggle/input')
    
    AUDIO_FILE = audio_files[0]
    print(f'Using: {AUDIO_FILE}')
    
    import torch
    device = 'cpu'
    if torch.cuda.is_available():
        try:
            cap = torch.cuda.get_device_capability(0)
            if cap >= (7, 0):
                device = 'cuda'
            else:
                print(f'GPU capability {cap} too old, using CPU instead.')
        except Exception as e:
            print(f'GPU check failed ({e}), using CPU instead.')
    
    model = stable_whisper.load_model(WHISPER_MODEL, device=device)
    result = model.transcribe(AUDIO_FILE, language=LANGUAGE, word_timestamps=True, verbose=False)
    
    base = os.path.splitext(os.path.basename(AUDIO_FILE))[0]
    word_srt = os.path.join(OUTPUT_DIR, f'{base}_word_level.srt')
    result.to_srt_vtt(word_srt, word_level=True, tag=('', ''))
    
    sent_srt = os.path.join(OUTPUT_DIR, f'{base}_sentence.srt')
    result.to_srt_vtt(sent_srt, word_level=False)
    
    print('Done! Files saved to /kaggle/working')
    

    Step 3: Pull Your Output

    Once the kernel finishes running, use the Kaggle API to pull your output files directly to your computer:

    kaggle kernels push
    kaggle kernels output <your-kernel-name> -p ./output

    Step 4: Import Into Your Video Editor

    Bring the exported SRT files into your video editor (CapCut, Premiere, etc.) to add synced captions to your video.

    Wrap-Up

    That’s it — accurate, free subtitles without ever handing your audio to a third-party website. If you found this useful, subscribe for more tutorials like this.