Skip to content
2 min read · 348 words

Function: buildNativeTtsInvocation()

ts
function buildNativeTtsInvocation(input: {
  command?: string;
  extraArgs?: string[];
  outPath: string;
  pitch?: number;
  platform: NativeTtsPlatform;
  rate?: number;
  text: string;
  voice?: string;
  wordsPerMinute?: number;
}): {
  args: string[];
  cmd: string;
};

Defined in: src/batteries/tts/native/helpers.ts:109

Build the { cmd, args } invocation for one native TTS synthesis call. Pure and side-effect-free.

Parameters

ParameterTypeDescription
input{ command?: string; extraArgs?: string[]; outPath: string; pitch?: number; platform: NativeTtsPlatform; rate?: number; text: string; voice?: string; wordsPerMinute?: number; }-
input.command?stringOptional executable override (default: say/espeak-ng/powershell.exe).
input.extraArgs?string[]Optional extra args inserted before the platform-specific flags.
input.outPathstringThe scratch WAV output path the binary writes to.
input.pitch?numberOptional espeak-ng pitch (0–99).
input.platformNativeTtsPlatformThe target platform.
input.rate?numberOptional resolved -10..10 rate for PowerShell (win32 only).
input.textstringThe text to synthesize.
input.voice?stringOptional voice name.
input.wordsPerMinute?numberOptional resolved wpm for say/espeak-ng.

Returns

ts
{
  args: string[];
  cmd: string;
}

The { cmd, args } pair to hand to the executor.

NameTypeDefined in
argsstring[]src/batteries/tts/native/helpers.ts:119
cmdstringsrc/batteries/tts/native/helpers.ts:119

Remarks

The caller (the adapter) resolves every policy decision BEFORE calling this:

  • wordsPerMinute is the already-resolved wpm for say/espeak-ng (the adapter computes wordsPerMinute ?? clamp(round(175 * (rate ?? 1)), 80, 500)).
  • rate is the already-resolved -10..10 integer for PowerShell's SpeechSynthesizer.Rate (the adapter computes clamp(round(((rate ?? 1) - 1) * 10), -10, 10)). It is used ONLY on win32 and ignored on darwin/linux — the helper does NOT recompute it.
  • pitch is the espeak-ng -p value (0–99); ignored on darwin/win32.

On every platform, command (when supplied) overrides only the executable; the platform's own argument/script shape is still built around it. extraArgs are inserted before the voice/rate/pitch/text flags on darwin/linux; they are IGNORED on win32, where the entire synthesis is expressed as a single -Command PowerShell script (there is no positional-flag slot to forward them into safely).