🎥 Make videos programmatically with React
returns correct json
Patric Salvisberg3a2d0f1cde40
diff --git a/packages/install-whisper-cpp/src/transcribe.ts b/packages/install-whisper-cpp/src/transcribe.tsindex 00d3249767..ac08a359bf 100644--- a/packages/install-whisper-cpp/src/transcribe.ts+++ b/packages/install-whisper-cpp/src/transcribe.ts@@ -1,30 +1,72 @@import {exec} from 'node:child_process';-import {existsSync} from 'node:fs';+import fs, {existsSync} from 'node:fs';import os from 'node:os';+import path from 'node:path';+import util from 'node:util';-export const transcribe = async (- whisperPath: string,- modelPath: string,- inputPath: string,- outputPath: string,-) => {- const executable = os.platform() === 'win32' ? 'main.exe' : './main';+interface TranscribeProps {+ whisperPath: string;+ modelPath: string;+ inputPath: string;+ outputPath: string;+}- // check if whisper exists, throw error with good error message if not+const readJson = (tempPath: string) => {+ let jsonData;++ fs.readFile(tempPath, 'utf8', (err, data) => {+ if (err) {+ console.error('Error reading the file:', err);+ return;+ }++ // Parse the JSON data+ try {+ jsonData = JSON.parse(data);+ console.log('JSON data:', jsonData);++ // Now you can work with the parsed JSON object+ // For example, you can access properties like jsonData.propertyName+ } catch (parseError) {+ console.error('Error parsing JSON:', parseError);+ }+ });+ return jsonData;+};++const translateToTempFile = async (transcribeProps: TranscribeProps) => {+ const {whisperPath, inputPath, outputPath, modelPath} = transcribeProps;+ const promisifiedExec = util.promisify(exec);+ const executable =+ os.platform() === 'win32'+ ? path.join(whisperPath, 'main.exe')+ : path.join(whisperPath, './main');++ await promisifiedExec(+ `${executable} -f ${inputPath} --output-file ${outputPath} --output-json --max-len 1 -m ${modelPath}`,+ {cwd: whisperPath},+ );+};++export const transcribe = async (transcribeProps: TranscribeProps) => {+ // Check if whisper exists, throw an error with a good error message if not+ const {whisperPath, inputPath} = transcribeProps;if (!existsSync(whisperPath)) {- console.log(`Whisper does not exists at ${whisperPath}`);+ throw new Error(`Whisper does not exist at ${whisperPath}`);}- // check if file exists+ // Check if the file existsif (!existsSync(inputPath)) {- console.log(`Inputfile does not exist at ${inputPath}`);+ throw new Error(`Input file does not exist at ${inputPath}`);}- // should we allow any path or just accept the model name as prop?- // const modelPath = path.join(whisperPath, `ggml-${whisperModel}.bin`);+ const res = await translateToTempFile(transcribeProps);- exec(- `${executable} -f ${inputPath} --output-file ${outputPath} --output-json --max-len 1 -m ${modelPath}`,- {cwd: whisperPath},+ console.log('Res: ', res);++ const json = readJson(+ '/Users/patricsalvisberg/Documents/Develop/template-tiktok/translated.json',);++ return json;};