Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { ChildProcess, SpawnOptions } from 'node:child_process';
import { Readable } from 'node:stream';

export interface RecordingOptions {
/**
* Sample rate in Hz
* @default 16000
*/
sampleRate?: number;

/**
* Number of channels to record
* @default 1
*/
channels?: number;

/**
* Whether to compress the audio
* @default false
*/
compress?: boolean;

/**
* Audio threshold
* @default 0.5
*/
threshold?: number;

/**
* Threshold for starting recording
* @default null
*/
thresholdStart?: number | null;

/**
* Threshold for ending recording
* @default null
*/
thresholdEnd?: number | null;

/**
* Silence duration
* @default "1.0"
*/
silence?: string;

/**
* Recording program to use
* @default "sox"
*/
recorder?: string;

/**
* Whether to end recording on silence
* @default false
*/
endOnSilence?: boolean;

/**
* Audio file type
* @default "wav"
*/
audioType?: string;
}

export interface RecorderConfig {
cmd: string;
args: string[];
spawnOptions?: SpawnOptions;
}

export interface Recorder {
(options: RecordingOptions): RecorderConfig;
}

export class Recording {
constructor(options?: RecordingOptions);

/**
* The child process running the recorder
*/
process: ChildProcess;

/**
* Recording options
*/
options: Required<RecordingOptions>;

/**
* Start recording
*/
start(): Recording;

/**
* Stop recording
*/
stop(): void;

/**
* Pause recording
*/
pause(): void;

/**
* Resume recording
*/
resume(): void;

/**
* Check if recording is paused
*/
isPaused(): boolean;

/**
* Get the recording stream
*/
stream(): Readable;
}

/**
* Create a new recording instance
*/
export function record(options?: RecordingOptions): Recording;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "Record a microphone input stream",
"license": "ISC",
"main": "index.js",
"types": "index.d.ts",
"dependencies": {
"debug": "^2.6.8"
},
Expand Down