UNPKG

mic-ts

Version:

A simple stream wrapper for arecord (Linux (including Raspbian)) and sox (Mac/Windows). Returns a Passthrough stream object so that stream control like pause(), resume(), pipe(), etc. are all available.

57 lines (56 loc) 2.27 kB
import { PassThrough } from "stream"; import { IsSilence } from "./IsSilence.js"; import type { MicOptions } from "./MicOptions.js"; export declare abstract class Mic { /** * This instantiates the process arecord OR sox using the options specified */ abstract start(): void; /** * This kills the arecord OR sox process that was started in the start() routine. It uses the SIGTERM signal. */ abstract stop(): void; /** * This pauses the arecord OR sox process using the SIGSTOP signal. */ abstract pause(): void; /** * This resumes the arecord OR sox process using the SIGCONT signal. */ abstract resume(): void; /** * This returns a simple Transform stream that contains the data from the arecord OR sox process. This sream can be directly piped to a speaker sream OR a file stream. Further this provides a number of events triggered by the state of the stream: * - `silence`: This is emitted once when exitOnSilence number of consecutive frames of silence are found. * - `sound`: This is emitted if we hear something after a silence. * - `processExitComplete`: This is emitted once the arecord OR sox process exits. * - `startComplete`: This is emitted once the `start()` function is successfully executed. * - `stopComplete`: This is emitted once the `stop()` function is successfully executed. * - `pauseComplete`: This is emitted once the `pause()` function is successfully executed. * - `resumeComplete`: This is emitted once the `resume()` function is successfully executed. * - It further inherits all the Events from `Transform`. */ abstract getAudioStream(): PassThrough; } export declare class MicImpl implements Mic { private audioProcess; private infoStream; private audioStream; private debug; private arecordEncoding; private arecordEndian; private bitwidth; private arecordFormat; private endian; private channels; private rate; private encoding; private fileType; private device; constructor(options?: MicOptions); private getAudioProcessOptions; start(): void; stop(): void; pause(): void; resume(): void; getAudioStream(): IsSilence; }