Skip to content
1 min read · 289 words

@nhtio/adk/batteries/tts/native/helpers

Pure invocation builders for the OS-native TTS adapter — the platform-specific argument arrays the adapter shells out with. This module is the hermetic, unit-tested core: NO node builtins, NO I/O.

Remarks

buildNativeTtsInvocation is the pure function that turns a resolved platform + text + output path + optional voice/rate/pitch into the { cmd, args } pair the executor runs, per platform:

  • darwin: say -o <outPath> --data-format=LEI16@22050 [...extraArgs] [-v <voice>] [-r <wpm>] <text>. --data-format=LEI16@22050 makes say emit real 16-bit little-endian PCM WAV at 22050 Hz rather than its default AIFF, so the adapter can assert the RIFF/WAVE magic on every byte payload.
  • linux: espeak-ng -w <outPath> [...extraArgs] [-v <voice>] [-s <wpm>] [-p <pitch>] <text>.
  • win32: powershell.exe -NoProfile -NonInteractive -Command <script>, where <script> drives System.Speech.Synthesis.SpeechSynthesizer to write a WAV file, with every interpolated value (text, voice, outPath) passed through psSingleQuotedLiteral so an apostrophe in the text can never break out of the PowerShell string literal. The rate is a -10..10 integer (NOT a wpm) computed by the adapter and passed in as win32Rate.

The adapter computes the resolved values (words-per-minute, win32 rate int) and passes them in; this helper does NOT recompute rate policy — it only threads the numbers onto the right flag for the platform.

Functions

FunctionDescription
buildNativeTtsInvocationBuild the { cmd, args } invocation for one native TTS synthesis call. Pure and side-effect-free.
psSingleQuotedLiteralEncode s as a single-quoted PowerShell string literal: wrap in single quotes and double every internal single quote ('''). PowerShell single-quoted literals are verbatim — no variable interpolation, no escape sequences — so this is the only quoting rule needed.