transcribe.mjs
sha256:8d46372e39d2d5a54fd93a8b1c27922fe0d9b22a72197345f1d2c71701cc4ce2
feat(auth): persistent login system + C7 session introspection
Human
minor
⚠ breaking
16 days ago
| 1 | #!/usr/bin/env node |
| 2 | import '../lib/load-env.mjs'; |
| 3 | |
| 4 | /** |
| 5 | * Standalone transcription script. Transcribes audio/video to stdout or writes to vault. |
| 6 | * |
| 7 | * Usage: |
| 8 | * node scripts/transcribe.mjs <audio-or-video-path> # print transcript to stdout |
| 9 | * node scripts/transcribe.mjs <path> --write [output-path] # write vault note |
| 10 | * |
| 11 | * Requires OPENAI_API_KEY. Config: config/local.yaml. |
| 12 | */ |
| 13 | |
| 14 | import path from 'path'; |
| 15 | import { fileURLToPath } from 'url'; |
| 16 | import { transcribe } from '../lib/transcribe.mjs'; |
| 17 | import { loadConfig } from '../lib/config.mjs'; |
| 18 | import { writeNote } from '../lib/write.mjs'; |
| 19 | |
| 20 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 21 | const projectRoot = path.resolve(__dirname, '..'); |
| 22 | |
| 23 | async function main() { |
| 24 | const args = process.argv.slice(2); |
| 25 | const input = args[0]; |
| 26 | const writeIdx = args.indexOf('--write'); |
| 27 | const doWrite = writeIdx !== -1; |
| 28 | const outputPath = doWrite && args[writeIdx + 1] ? args[writeIdx + 1] : null; |
| 29 | |
| 30 | if (!input) { |
| 31 | console.error('Usage: node scripts/transcribe.mjs <audio-or-video-path> [--write [output-path]]'); |
| 32 | process.exit(1); |
| 33 | } |
| 34 | |
| 35 | try { |
| 36 | const { text, transcoded } = await transcribe(input); |
| 37 | if (transcoded) { |
| 38 | console.error('Transcoded with ffmpeg before Whisper (original file was over 25MB).'); |
| 39 | } |
| 40 | const bodyText = text || '(No speech detected)'; |
| 41 | if (doWrite) { |
| 42 | const config = loadConfig(projectRoot); |
| 43 | const baseName = path.basename(input, path.extname(input)); |
| 44 | const relPath = outputPath || `media/audio/${baseName}.md`; |
| 45 | const now = new Date().toISOString().slice(0, 10); |
| 46 | const body = |
| 47 | transcoded |
| 48 | ? '> *Transcoded for Whisper (ffmpeg) before upload.*\n\n' + bodyText |
| 49 | : bodyText; |
| 50 | writeNote(config.vault_path, relPath, { |
| 51 | body, |
| 52 | frontmatter: { source: 'audio', source_id: baseName, date: now, title: baseName }, |
| 53 | }); |
| 54 | console.log(`Written: ${relPath}`); |
| 55 | } else { |
| 56 | process.stdout.write(bodyText + '\n'); |
| 57 | } |
| 58 | process.exit(0); |
| 59 | } catch (e) { |
| 60 | console.error('transcribe:', e.message); |
| 61 | process.exit(2); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | main(); |
File History
2 commits
sha256:8d46372e39d2d5a54fd93a8b1c27922fe0d9b22a72197345f1d2c71701cc4ce2
feat(auth): persistent login system + C7 session introspection
Human
minor
⚠
16 days ago
sha256:6a102aafafdfe7e70a24f4e59740200f0ee713ce7915f1b53e9d4ba5ee8b4410
Initial Muse snapshot
Human
48 days ago