Skip to content

Instantly share code, notes, and snippets.

@dbreunig
Created September 26, 2022 21:46
Show Gist options
  • Save dbreunig/ddef313e01456ec63d3413e28244611f to your computer and use it in GitHub Desktop.
Save dbreunig/ddef313e01456ec63d3413e28244611f to your computer and use it in GitHub Desktop.
An example of transcribing an audio file with Whisper and loading its transcription data into a sqlite3 database for easy searching.
import whisper
import sqlite3
# Load the model. Pick from tiny, base, small, medium, large.
model = whisper.load_model("base")
# Transcribe the local file 'podcast.mp3'. Change as necessary
transcription = model.transcribe("podcast.mp3")
# Create the database and table
con = sqlite3.connect("transcription.db")
cur = con.cursor()
cur.execute("CREATE TABLE segments(id, seek, start, end, text)")
# Prepare the segment dicts for bulk insertion
segments = []
for s in transcription['segments']:
segments.append((s['id'], s['seek'], s['start'], s['end'], s['text']))
# Insert the segment tuples into the table
cur.executemany("INSERT INTO segments VALUES(?, ?, ?, ?, ?)", segments)
con.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment