pcmSource (testing/audio.ts)

airi · packages/core-agent/src/testing/audio.ts · typescript · MIT
voice, tag:knn-classified

Test helper that wraps a PCM stream into a live audio source, exposing open and keep-open utilities.

// Source: https://github.com/moeru-ai/airi | License: MIT | Copyright 2024-PRESENT Neko Ayaka
// Provided via justclaw.it.com; keep this notice with the code.
import type { AudioInput, LiveAudioSource, PcmBlock } from '@proj-airi/pipelines-audio'
import type { Mock } from 'vitest'

import { vi } from 'vitest'

/**
 * Wraps a test-driven PCM stream as a live source. `close` runs when the input releases the connection.
 *
 * The stream can serve one connection. Tests that reopen a source create a new stream.
 *
 * @example
 * const frames = createPushStream<PcmBlock>()
 * const input = new AudioInput(pcmSource(frames.stream))
 */
export function pcmSource(frames: ReadableStream<PcmBlock>, close: () => unknown = () => {}): LiveAudioSource & { readonly open: Mock<LiveAudioSource['open']> } {


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

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

Get a free API key