2020-08-13 13:05:37 +02:00
|
|
|
import {IDevice} from "tc-shared/audio/recorder";
|
|
|
|
import {Registry} from "tc-shared/events";
|
|
|
|
import {Filter, FilterType, FilterTypeClass} from "tc-shared/voice/Filter";
|
2020-03-30 13:44:18 +02:00
|
|
|
|
|
|
|
export enum InputConsumerType {
|
|
|
|
CALLBACK,
|
|
|
|
NODE,
|
|
|
|
NATIVE
|
|
|
|
}
|
2020-08-19 19:33:57 +02:00
|
|
|
export interface CallbackInputConsumer {
|
|
|
|
type: InputConsumerType.CALLBACK;
|
2020-03-30 13:44:18 +02:00
|
|
|
callback_audio?: (buffer: AudioBuffer) => any;
|
|
|
|
callback_buffer?: (buffer: Float32Array, samples: number, channels: number) => any;
|
|
|
|
}
|
|
|
|
|
2020-08-19 19:33:57 +02:00
|
|
|
export interface NodeInputConsumer {
|
|
|
|
type: InputConsumerType.NODE;
|
2020-03-30 13:44:18 +02:00
|
|
|
callback_node: (source_node: AudioNode) => any;
|
|
|
|
callback_disconnect: (source_node: AudioNode) => any;
|
|
|
|
}
|
|
|
|
|
2020-08-19 19:33:57 +02:00
|
|
|
export interface NativeInputConsumer {
|
|
|
|
type: InputConsumerType.NATIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type InputConsumer = CallbackInputConsumer | NodeInputConsumer | NativeInputConsumer;
|
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
|
|
|
|
export enum InputState {
|
2020-08-19 19:33:57 +02:00
|
|
|
/* Input recording has been paused */
|
2020-03-30 13:44:18 +02:00
|
|
|
PAUSED,
|
2020-08-19 19:33:57 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Recording has been requested, and is currently initializing.
|
|
|
|
* This state may persist, when the audio context hasn't been initialized yet
|
|
|
|
*/
|
2020-03-30 13:44:18 +02:00
|
|
|
INITIALIZING,
|
2020-08-19 19:33:57 +02:00
|
|
|
|
|
|
|
/* we're currently recording the input */
|
|
|
|
RECORDING
|
2020-03-30 13:44:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export enum InputStartResult {
|
|
|
|
EOK = "eok",
|
|
|
|
EUNKNOWN = "eunknown",
|
2020-08-19 19:33:57 +02:00
|
|
|
EDEVICEUNKNOWN = "edeviceunknown",
|
2020-03-30 13:44:18 +02:00
|
|
|
EBUSY = "ebusy",
|
|
|
|
ENOTALLOWED = "enotallowed",
|
|
|
|
ENOTSUPPORTED = "enotsupported"
|
|
|
|
}
|
|
|
|
|
2020-08-13 13:05:37 +02:00
|
|
|
export interface InputEvents {
|
|
|
|
notify_voice_start: {},
|
|
|
|
notify_voice_end: {}
|
|
|
|
}
|
|
|
|
|
2020-03-30 13:44:18 +02:00
|
|
|
export interface AbstractInput {
|
2020-08-13 13:05:37 +02:00
|
|
|
readonly events: Registry<InputEvents>;
|
2020-03-30 13:44:18 +02:00
|
|
|
|
2020-08-13 13:05:37 +02:00
|
|
|
currentState() : InputState;
|
2020-03-30 13:44:18 +02:00
|
|
|
|
|
|
|
start() : Promise<InputStartResult>;
|
|
|
|
stop() : Promise<void>;
|
|
|
|
|
2020-08-19 19:33:57 +02:00
|
|
|
/*
|
|
|
|
* Returns true if the input is currently filtered.
|
|
|
|
* If the current state isn't recording, than it will return true.
|
|
|
|
*/
|
|
|
|
isFiltered() : boolean;
|
|
|
|
|
|
|
|
currentDeviceId() : string | undefined;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This method should not throw!
|
|
|
|
* If the target device is unknown than it should return EDEVICEUNKNOWN on start.
|
|
|
|
* After changing the device, the input state falls to InputState.PAUSED.
|
|
|
|
*/
|
2020-09-02 11:41:51 +02:00
|
|
|
setDeviceId(device: string) : Promise<void>;
|
2020-03-30 13:44:18 +02:00
|
|
|
|
2020-08-13 13:05:37 +02:00
|
|
|
currentConsumer() : InputConsumer | undefined;
|
|
|
|
setConsumer(consumer: InputConsumer) : Promise<void>;
|
2020-03-30 13:44:18 +02:00
|
|
|
|
2020-08-13 13:05:37 +02:00
|
|
|
supportsFilter(type: FilterType) : boolean;
|
|
|
|
createFilter<T extends FilterType>(type: T, priority: number) : FilterTypeClass<T>;
|
|
|
|
removeFilter(filter: Filter);
|
2020-08-19 19:33:57 +02:00
|
|
|
/* resetFilter(); */
|
2020-03-30 13:44:18 +02:00
|
|
|
|
2020-08-13 13:05:37 +02:00
|
|
|
getVolume() : number;
|
|
|
|
setVolume(volume: number);
|
2020-03-30 13:44:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface LevelMeter {
|
2020-08-13 13:05:37 +02:00
|
|
|
device() : IDevice;
|
2020-03-30 13:44:18 +02:00
|
|
|
|
|
|
|
set_observer(callback: (value: number) => any);
|
|
|
|
|
2020-08-13 13:05:37 +02:00
|
|
|
destroy();
|
2019-05-20 18:57:14 +02:00
|
|
|
}
|