Telephony Audio Processing Utility (src/telephony-audio.ts)

openclaw-zero-token · extensions/voice-call/src/telephony-audio.ts · typescript · MIT
voice, lang:typescript, tag:resampling

Provides audio resampling and conversion functions for telephony standards like Mu-law. Use this for preparing raw audio data for voice-over-IP or telephony integration.

// Source: https://github.com/linuxhsj/openclaw-zero-token | License: MIT | Copyright 2025 Peter Steinberger
// Provided via justclaw.it.com; keep this notice with the code.
const TELEPHONY_SAMPLE_RATE = 8000;
const RESAMPLE_FILTER_TAPS = 31;
const RESAMPLE_CUTOFF_GUARD = 0.94;

function clamp16(value: number): number {
  return Math.max(-32768, Math.min(32767, value));
}

function sinc(x: number): number {
  if (x === 0) {
    return 1;
  }
  return Math.sin(Math.PI * x) / (Math.PI * x);
}

/**
 * Build a finite low-pass kernel centered on `srcPos`.
 * The kernel is windowed (Hann) to reduce ringing artifacts.
 */
function sampleBandlimited(
  input: Buffer,
  inputSamples: number,
  srcPos: number,
  cutoffCyclesPerSample: number,
): number {
  const half = Math.floor(RESAMPLE_FILTER_TAP

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key