@senad-d/micme 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ export function stripTerminalControlSequences(value: string) {
2
+ return value
3
+ .replace(/\x1b\][^\x07]*(?:\x07|\x1b\\)/g, " ")
4
+ .replace(/\x1b[PX^_][\s\S]*?(?:\x07|\x1b\\)/g, " ")
5
+ .replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, " ")
6
+ .replace(/\x1b[ -/]*[@-~]/g, " ")
7
+ .replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, " ");
8
+ }
9
+
10
+ export function sanitizeTerminalText(value: string) {
11
+ return stripTerminalControlSequences(value).replace(/\s+/g, " ").trim();
12
+ }
13
+
14
+ export function sanitizeTerminalOutput(value: string) {
15
+ return stripTerminalControlSequences(value)
16
+ .replace(/\r\n/g, "\n")
17
+ .replace(/\r/g, "\n")
18
+ .split("\n")
19
+ .map((line) => line.trimEnd())
20
+ .join("\n")
21
+ .trim();
22
+ }
@@ -5,7 +5,7 @@ import { basename, join } from "node:path";
5
5
  import { resolveTranscriptionPlan, formatTranscriptionPlan } from "./backends.ts";
6
6
  import { env, getTranscribeTimeoutMs, getTranslateToEnglishLanguage } from "./config.ts";
7
7
  import { ensureWhisperCppModel, getPythonWhisperModelName } from "./models.ts";
8
- import { formatRunExit, replacePlaceholders, runProcess, runShell } from "./processes.ts";
8
+ import { formatProcessOutput, formatRunExit, replacePlaceholders, runProcess, runShell } from "./processes.ts";
9
9
 
10
10
  export { getWhisperCppBinary, getWhisperStreamBinary, resolveExecutableConfig } from "./backends.ts";
11
11
 
@@ -34,7 +34,7 @@ export async function transcribeWithCustomCommand(template: string, audioPath: s
34
34
  const command = replacePlaceholders(template, { audio: audioPath, tempDir, transcript: transcriptPath });
35
35
  const result = await runShell(command, getTranscribeTimeoutMs());
36
36
  if (result.code !== 0) {
37
- throw new Error(`MICME_TRANSCRIBE_COMMAND failed (${formatRunExit(result)}):\n${result.stderr || result.stdout}`);
37
+ throw new Error(`MICME_TRANSCRIBE_COMMAND failed (${formatRunExit(result)}):\n${formatProcessOutput(result.stderr, result.stdout)}`);
38
38
  }
39
39
 
40
40
  if (existsSync(transcriptPath)) {
@@ -66,7 +66,7 @@ export async function transcribeWithWhisperCpp(
66
66
 
67
67
  const result = await runProcess(binary, args, getTranscribeTimeoutMs());
68
68
  if (result.code !== 0) {
69
- throw new Error(`whisper.cpp failed (${formatRunExit(result)}):\n${result.stderr || result.stdout}`);
69
+ throw new Error(`whisper.cpp failed (${formatRunExit(result)}):\n${formatProcessOutput(result.stderr, result.stdout)}`);
70
70
  }
71
71
 
72
72
  const outputPath = `${outputBase}.txt`;
@@ -111,7 +111,7 @@ export async function transcribeWithOpenAiWhisper(binary: string, audioPath: str
111
111
 
112
112
  const result = await runProcess(binary, args, getTranscribeTimeoutMs());
113
113
  if (result.code !== 0) {
114
- throw new Error(`openai-whisper failed (${formatRunExit(result)}):\n${result.stderr || result.stdout}`);
114
+ throw new Error(`openai-whisper failed (${formatRunExit(result)}):\n${formatProcessOutput(result.stderr, result.stdout)}`);
115
115
  }
116
116
 
117
117
  const txtName = basename(audioPath).replace(/\.[^.]+$/, ".txt");