import fs from 'node:fs'; import { execFileSync } from 'node:child_process'; import * as db from './db.js'; const wav = '/tmp/test.wav'; const WH = '/opt/whisper.cpp/build/bin/whisper-cli'; const MODEL = '/opt/whisper.cpp/models/ggml-small.bin'; execFileSync('ffmpeg', ['-y', '-i', wav, '-codec:a', 'libmp3lame', '-qscale:a', '4', '/opt/callrec/recordings/test.mp3']); execFileSync(WH, ['-m', MODEL, '-f', wav, '-l', 'de', '-ml', '1', '-sow', '-oj', '-of', '/tmp/test'], { maxBuffer: 1 << 24 }); const j = JSON.parse(fs.readFileSync('/tmp/test.json', 'utf8')); const words = []; let tr = ''; for (const s of j.transcription || []) { const t = (s.text || '').trim(); if (!t) continue; words.push({ word: t, t_start_ms: s.offsets.from, t_end_ms: s.offsets.to }); tr += (tr ? ' ' : '') + t; } const durMs = words.length ? words[words.length - 1].t_end_ms : 0; const id = await db.addRecording({ title: 'Selbsttest (deutsche TTS)', mp3_file: 'test.mp3', device: 'test', duration_ms: durMs, transcript: tr, language: 'de', status: 'done' }); await db.addWords(id, words); console.log('SEEDED id=' + id + ' words=' + words.length + ' text="' + tr + '"'); process.exit(0);