mcp-speechmatics-transcribe 0.1.18 → 0.1.19
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.
- package/.env.example +1 -3
- package/README.md +2 -6
- package/cli.js +1 -2
- package/modules/config.js +4 -6
- package/modules/media-preparation.js +2 -2
- package/modules/options.js +2 -4
- package/modules/tools.js +1 -2
- package/modules/transcribe.js +2 -6
- package/package.json +1 -1
package/.env.example
CHANGED
|
@@ -33,6 +33,4 @@ SPEECHMATICS_FRAME_MAX_HEIGHT=1080
|
|
|
33
33
|
SPEECHMATICS_FRAME_CHANGE_THRESHOLD=4.5
|
|
34
34
|
|
|
35
35
|
# Skip retained audio below this duration, before API calls.
|
|
36
|
-
|
|
37
|
-
# Prepare media only, without credentials or Speechmatics requests.
|
|
38
|
-
SPEECHMATICS_PREPARE_ONLY=false
|
|
36
|
+
SPEECHMATICS_MIN_LENGTH=0
|
package/README.md
CHANGED
|
@@ -58,11 +58,8 @@ Silence removal is enabled for all audio and video formats. By default, it remov
|
|
|
58
58
|
intervals below -40 dB lasting at least 3 seconds, retaining a 0.3-second margin
|
|
59
59
|
at each end. Lower the threshold for quiet speech, or set removeSilence=false
|
|
60
60
|
(CLI: --no-remove-silence) to disable it. An entirely silent input is skipped
|
|
61
|
-
without submitting a Speechmatics job. Set
|
|
61
|
+
without submitting a Speechmatics job. Set minLength (CLI: --min-length)
|
|
62
62
|
to skip recordings whose retained audio is too short; the default is 0.
|
|
63
|
-
Use prepareOnly=true (CLI: --prepare-only) to prepare media and optional screenshots
|
|
64
|
-
without credentials or API calls. The result reports prepared or skipped status,
|
|
65
|
-
paths, originalSeconds, and compactSeconds; no transcript is created.
|
|
66
63
|
|
|
67
64
|
Enable extractFrames to save PNG screenshots alongside a video transcription.
|
|
68
65
|
These can help with illustrated notes and slide references. The default changes
|
|
@@ -133,8 +130,7 @@ Source installations otherwise load .env from the package directory.
|
|
|
133
130
|
| SPEECHMATICS_DIARIZATION | speaker | Speaker attribution; MCP only exposes disabling it |
|
|
134
131
|
| SPEECHMATICS_AUDIO_EVENTS | true | Enable events for Standard and Enhanced |
|
|
135
132
|
| SPEECHMATICS_TIMEOUT_SECONDS | 900 | Upload and processing timeout in seconds |
|
|
136
|
-
|
|
|
137
|
-
| SPEECHMATICS_PREPARE_ONLY | false | Prepare media and screenshots without API calls |
|
|
133
|
+
| SPEECHMATICS_MIN_LENGTH | 0 | Skip retained audio below this duration before API calls |
|
|
138
134
|
| SPEECHMATICS_REMOVE_SILENCE | true | Remove silent intervals before upload |
|
|
139
135
|
| SPEECHMATICS_SILENCE_THRESHOLD_DB | -40 | Silence threshold in dB |
|
|
140
136
|
| SPEECHMATICS_SILENCE_MINIMUM_SECONDS | 3 | Minimum silent interval |
|
package/cli.js
CHANGED
|
@@ -17,8 +17,7 @@ const program = new Command()
|
|
|
17
17
|
.addOption(new Option("--model <model>", `Model (default: ${defaults.model})`).choices(optionFields.model.options))
|
|
18
18
|
.option("--language <code>", `Language (default: ${defaults.language}); use multi with multilingual models`)
|
|
19
19
|
.addOption(new Option("--diarization <mode>", `Diarization (default: ${defaults.diarization})`).choices(optionFields.diarization.options))
|
|
20
|
-
.option("--
|
|
21
|
-
.option("--prepare-only", "Prepare media and screenshots without credentials or API calls")
|
|
20
|
+
.option("--min-length <seconds>", "Skip audio shorter than this after preparation (default: 0)", Number)
|
|
22
21
|
.option("--remove-silence", "Remove silence before upload (enabled by default)")
|
|
23
22
|
.option("--no-remove-silence", "Disable silence removal")
|
|
24
23
|
.option("--silence-threshold-db <db>", "Silence threshold in dB", Number)
|
package/modules/config.js
CHANGED
|
@@ -5,8 +5,7 @@ import { defaults, optionsSchema } from "./options.js";
|
|
|
5
5
|
|
|
6
6
|
const booleanSetting = z.enum(["true", "false"]).transform((value) => value === "true");
|
|
7
7
|
const environmentSchema = z.object({
|
|
8
|
-
|
|
9
|
-
SPEECHMATICS_PREPARE_ONLY: booleanSetting.optional(),
|
|
8
|
+
SPEECHMATICS_MIN_LENGTH: z.coerce.number().optional(),
|
|
10
9
|
SPEECHMATICS_REMOVE_SILENCE: booleanSetting.optional(),
|
|
11
10
|
SPEECHMATICS_SILENCE_THRESHOLD_DB: z.coerce.number().optional(),
|
|
12
11
|
SPEECHMATICS_SILENCE_MINIMUM_SECONDS: z.coerce.number().optional(),
|
|
@@ -40,7 +39,7 @@ export function parseTokens(source) {
|
|
|
40
39
|
return parsed.data;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
export async function loadConfig(overrides = {}, { requireTokens = true
|
|
42
|
+
export async function loadConfig(overrides = {}, { requireTokens = true } = {}) {
|
|
44
43
|
const environment = { ...process.env };
|
|
45
44
|
const loaded = dotenv.config({
|
|
46
45
|
path: process.env.SPEECHMATICS_ENV_FILE ?? fileURLToPath(new URL("../.env", import.meta.url)),
|
|
@@ -51,8 +50,7 @@ export async function loadConfig(overrides = {}, { requireTokens = true, allowPr
|
|
|
51
50
|
|
|
52
51
|
const env = environmentSchema.parse(environment);
|
|
53
52
|
const environmentOptions = {
|
|
54
|
-
|
|
55
|
-
prepareOnly: env.SPEECHMATICS_PREPARE_ONLY,
|
|
53
|
+
minLength: env.SPEECHMATICS_MIN_LENGTH,
|
|
56
54
|
removeSilence: env.SPEECHMATICS_REMOVE_SILENCE,
|
|
57
55
|
silenceThresholdDb: env.SPEECHMATICS_SILENCE_THRESHOLD_DB,
|
|
58
56
|
silenceMinimumSeconds: env.SPEECHMATICS_SILENCE_MINIMUM_SECONDS,
|
|
@@ -73,7 +71,7 @@ export async function loadConfig(overrides = {}, { requireTokens = true, allowPr
|
|
|
73
71
|
const options = optionsSchema.parse({
|
|
74
72
|
...defaults, ...defined(environmentOptions), ...defined(overrides),
|
|
75
73
|
});
|
|
76
|
-
const needsTokens = requireTokens
|
|
74
|
+
const needsTokens = requireTokens;
|
|
77
75
|
if (needsTokens && environment.SPEECHMATICS_TOKENS === undefined) throw new Error("Set SPEECHMATICS_TOKENS in the process environment or .env file.");
|
|
78
76
|
const tokens = needsTokens ? parseTokens(environment.SPEECHMATICS_TOKENS) : [];
|
|
79
77
|
return { tokens, options };
|
|
@@ -27,7 +27,7 @@ export function parseAnalysis(stdout, stderr, options) {
|
|
|
27
27
|
export async function prepareMedia(input, directory, id, options) {
|
|
28
28
|
const compressed = [".mp3", ".aac", ".ogg", ".m4a", ".flac"].includes(extname(input).toLowerCase());
|
|
29
29
|
const output = join(directory, `audio-${id}.mp3`);
|
|
30
|
-
if (!options.removeSilence && !options.extractFrames && !options.
|
|
30
|
+
if (!options.removeSilence && !options.extractFrames && !options.minLength) {
|
|
31
31
|
const conversion = compressed ? null : await convertAudio(input, output);
|
|
32
32
|
return { file: compressed ? input : output, conversion, timeline: null, timelineFile: null, frames: null };
|
|
33
33
|
}
|
|
@@ -43,7 +43,7 @@ export async function prepareMedia(input, directory, id, options) {
|
|
|
43
43
|
const { timeline, hasVideo, normalizeAudio, mp3Audio } = parseAnalysis(analysis.stdout, analysis.stderr, options);
|
|
44
44
|
const timelineFile = join(directory, `timeline-${id}.json`);
|
|
45
45
|
await writeFile(timelineFile, JSON.stringify({ source: input, ...timeline }, null, 2) + "\n", { flag: "wx" });
|
|
46
|
-
if (!timeline.segments.length || timeline.compactSeconds < 0.01 || timeline.compactSeconds < options.
|
|
46
|
+
if (!timeline.segments.length || timeline.compactSeconds < 0.01 || timeline.compactSeconds < options.minLength) return { file: null, conversion: null, timeline, timelineFile, frames: null, skipped: true };
|
|
47
47
|
const cut = timeline.compactSeconds < timeline.originalSeconds - 0.000001;
|
|
48
48
|
const renderAudio = cut || normalizeAudio || !compressed;
|
|
49
49
|
const copyAudio = renderAudio && !cut && !normalizeAudio && mp3Audio;
|
package/modules/options.js
CHANGED
|
@@ -6,8 +6,7 @@ export const defaults = {
|
|
|
6
6
|
diarization: "speaker",
|
|
7
7
|
audioEvents: true,
|
|
8
8
|
timeoutSeconds: 900,
|
|
9
|
-
|
|
10
|
-
prepareOnly: false,
|
|
9
|
+
minLength: 0,
|
|
11
10
|
removeSilence: true,
|
|
12
11
|
silenceThresholdDb: -40,
|
|
13
12
|
silenceMinimumSeconds: 3,
|
|
@@ -26,8 +25,7 @@ export const optionFields = {
|
|
|
26
25
|
diarization: z.enum(["none", "speaker", "channel"]),
|
|
27
26
|
audioEvents: z.boolean(),
|
|
28
27
|
timeoutSeconds: z.int().positive().max(86400),
|
|
29
|
-
|
|
30
|
-
prepareOnly: z.boolean(),
|
|
28
|
+
minLength: z.number().nonnegative(),
|
|
31
29
|
removeSilence: z.boolean(),
|
|
32
30
|
silenceThresholdDb: z.number().min(-100).max(-1),
|
|
33
31
|
silenceMinimumSeconds: z.number().positive().max(3600),
|
package/modules/tools.js
CHANGED
|
@@ -18,8 +18,7 @@ export function createTools(configuredDefaults) {
|
|
|
18
18
|
language: optionFields.language.optional().describe(`Configured default: ${configuredDefaults.language}. Language code such as pl or en for enhanced/standard. Use multi for MULTILANGUAGE models melia-1 and oak-1.`),
|
|
19
19
|
disableDiarization: z.boolean().optional().describe(`Configured speaker diarization: ${configuredDefaults.diarization === "none" ? "disabled" : "enabled"}. Set true to disable it. Omit or pass false to use the server setting.`),
|
|
20
20
|
audioEvents: optionFields.audioEvents.optional().describe(`Configured default: ${configuredDefaults.audioEvents}. Detect laughter, music, and applause with Standard/Enhanced. Automatically disabled for melia-1/oak-1. Set false to disable.`),
|
|
21
|
-
|
|
22
|
-
prepareOnly: optionFields.prepareOnly.optional().describe(`Configured default: ${configuredDefaults.prepareOnly}. Prepare media and optional frames without credentials or API calls; returns paths and durations instead of a transcript.`),
|
|
21
|
+
minLength: optionFields.minLength.optional().describe(`Configured default: ${configuredDefaults.minLength}. Skip when retained audio is shorter than this many seconds, before any API call.`),
|
|
23
22
|
removeSilence: optionFields.removeSilence.optional().describe(`Configured default: ${configuredDefaults.removeSilence}. Remove silence from any supported input before sending audio; false disables it.`),
|
|
24
23
|
silenceThresholdDb: optionFields.silenceThresholdDb.optional().describe(`Configured default: ${configuredDefaults.silenceThresholdDb}. Silence detection threshold in dB; quiet speech may require a lower threshold.`),
|
|
25
24
|
silenceMinimumSeconds: optionFields.silenceMinimumSeconds.optional().describe(`Configured default: ${configuredDefaults.silenceMinimumSeconds}. Minimum silence duration in seconds before a cut.`),
|
package/modules/transcribe.js
CHANGED
|
@@ -21,7 +21,7 @@ export async function transcribe(file, overrides = {}) {
|
|
|
21
21
|
const input = resolve(file);
|
|
22
22
|
const inputName = basename(input);
|
|
23
23
|
if (!(await stat(input)).isFile()) throw new Error(`Expected an audio or video file: ${input}`);
|
|
24
|
-
const { tokens, options } = await loadConfig(overrides
|
|
24
|
+
const { tokens, options } = await loadConfig(overrides);
|
|
25
25
|
options.audioEvents &&= ["standard", "enhanced"].includes(options.model);
|
|
26
26
|
|
|
27
27
|
const started = Date.now();
|
|
@@ -52,11 +52,7 @@ export async function transcribe(file, overrides = {}) {
|
|
|
52
52
|
record.audioDurationSeconds = 0;
|
|
53
53
|
record.audioDurationHours = 0;
|
|
54
54
|
record.originalDurationSeconds = preparation.timeline.originalSeconds;
|
|
55
|
-
result = { ...media, status: "skipped", reason: preparation.timeline.compactSeconds < 0.01 ? "No audio remains after silence removal." : "Prepared audio is shorter than
|
|
56
|
-
} else if (options.prepareOnly) {
|
|
57
|
-
record.status = "prepared";
|
|
58
|
-
record.originalDurationSeconds = media.originalSeconds;
|
|
59
|
-
result = { ...media, status: "prepared", file: preparation.file, convertedFile, conversion };
|
|
55
|
+
result = { ...media, status: "skipped", reason: preparation.timeline.compactSeconds < 0.01 ? "No audio remains after silence removal." : "Prepared audio is shorter than minLength." };
|
|
60
56
|
} else {
|
|
61
57
|
await initializeUsage(tokens).catch(() => {});
|
|
62
58
|
record.reservationExpiresAt = new Date(Date.now() + options.timeoutSeconds * 1000).toISOString();
|