Voice Transcript Turn Assembler (src/turns.js)

synaplan · sidecars/synaplan-voice/src/turns.js · javascript · Apache-2.0
voice, realtime, chat, lang:javascript

Processes raw audio-to-text streams into coherent conversation turns. Use this to manage turn-taking logic in real-time voice applications.

// Source: https://github.com/metadist/synaplan | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
export const TURN_SETTLE_MS = 1500

const otherRole = (role) => (role === 'user' ? 'assistant' : 'user')

/** Drops sound tags such as "[hum]" or "[burp]" that are not words. */
export function spokenText(text) {
  return String(text ?? '')
    .replace(/\[[^\]\n]{1,32}\]/g, ' ')
    .replace(/[ \t]{2,}/g, ' ')
    .trim()
}

/**
 * Builds one transcript turn per speaker from provider pieces, so the chat
 * shows one growing message per turn.
 *
 * Full-duplex providers interleave the caller's and the assistant's words,
 * and an echo of the reply can reach the microphone. A speaker cha

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

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

Get a free API key