native-mic-capacitor
v0.0.6
Published
Get native stream of your microphone
Readme
native-mic-capacitor
Get native stream of your microphone
Install
npm install native-mic-capacitor
npx cap syncAPI
isAvailable()checkPermissions()requestPermissions()getDevices()setPreferredInput(...)setOutputRoute(...)startCapture(...)stopCapture(...)setMicEnabled(...)getState()getDiagnostics()webrtcIsAvailable()webrtcConnect(...)webrtcDisconnect(...)webrtcSendDataMessage(...)webrtcSetMicEnabled(...)webrtcSetPreferredInput(...)webrtcSetOutputRoute(...)webrtcGetState(...)webrtcGetDiagnostics(...)addListener('micStateChanged', ...)addListener('micPcmChunk', ...)addListener('micAudioLevel', ...)addListener('micRouteChanged', ...)addListener('micInterruption', ...)addListener('micError', ...)addListener('webrtcStateChanged', ...)addListener('webrtcDataMessage', ...)addListener('webrtcTrackStarted', ...)addListener('webrtcTrackStopped', ...)addListener('webrtcLocalAudioLevel', ...)addListener('webrtcRemoteAudioLevel', ...)addListener('webrtcError', ...)removeAllListeners()- Interfaces
- Type Aliases
isAvailable()
isAvailable() => Promise<{ available: boolean; reason?: string; }>Returns: Promise<{ available: boolean; reason?: string; }>
checkPermissions()
checkPermissions() => Promise<{ microphone: MicPermissionState; }>Returns: Promise<{ microphone: MicPermissionState; }>
requestPermissions()
requestPermissions() => Promise<{ microphone: MicPermissionState; }>Returns: Promise<{ microphone: MicPermissionState; }>
getDevices()
getDevices() => Promise<{ inputs: MicDevice[]; selectedInputId?: string; }>Returns: Promise<{ inputs: MicDevice[]; selectedInputId?: string; }>
setPreferredInput(...)
setPreferredInput(options: { inputId: string | null; }) => Promise<void>| Param | Type |
| ------------- | ----------------------------------------- |
| options | { inputId: string | null; } |
setOutputRoute(...)
setOutputRoute(options: { route: OutputRoute; }) => Promise<void>| Param | Type |
| ------------- | --------------------------------------------------------------- |
| options | { route: OutputRoute; } |
startCapture(...)
startCapture(options: StartCaptureOptions) => Promise<StartCaptureResult>| Param | Type |
| ------------- | ------------------------------------------------------------------- |
| options | StartCaptureOptions |
Returns: Promise<StartCaptureResult>
stopCapture(...)
stopCapture(options: StopCaptureOptions) => Promise<StopCaptureResult>| Param | Type |
| ------------- | ----------------------------------------------------------------- |
| options | StopCaptureOptions |
Returns: Promise<StopCaptureResult>
setMicEnabled(...)
setMicEnabled(options: { captureId: string; enabled: boolean; }) => Promise<void>| Param | Type |
| ------------- | ----------------------------------------------------- |
| options | { captureId: string; enabled: boolean; } |
getState()
getState() => Promise<{ state: 'idle' | 'running' | 'paused'; }>Returns: Promise<{ state: 'idle' | 'running' | 'paused'; }>
getDiagnostics()
getDiagnostics() => Promise<Record<string, unknown>>Returns: Promise<Record<string, unknown>>
webrtcIsAvailable()
webrtcIsAvailable() => Promise<{ available: boolean; reason?: string; }>Returns: Promise<{ available: boolean; reason?: string; }>
webrtcConnect(...)
webrtcConnect(options: NativeWebRTCConnectOptions) => Promise<NativeWebRTCConnectResult>| Param | Type |
| ------------- | --------------------------------------------------------------------------------- |
| options | NativeWebRTCConnectOptions |
Returns: Promise<NativeWebRTCConnectResult>
webrtcDisconnect(...)
webrtcDisconnect(options: { connectionId: string; reason?: string; }) => Promise<void>| Param | Type |
| ------------- | ------------------------------------------------------- |
| options | { connectionId: string; reason?: string; } |
webrtcSendDataMessage(...)
webrtcSendDataMessage(options: { connectionId: string; data: string; }) => Promise<void>| Param | Type |
| ------------- | ---------------------------------------------------- |
| options | { connectionId: string; data: string; } |
webrtcSetMicEnabled(...)
webrtcSetMicEnabled(options: { connectionId: string; enabled: boolean; }) => Promise<void>| Param | Type |
| ------------- | -------------------------------------------------------- |
| options | { connectionId: string; enabled: boolean; } |
webrtcSetPreferredInput(...)
webrtcSetPreferredInput(options: { connectionId: string; inputId: string | null; }) => Promise<void>| Param | Type |
| ------------- | --------------------------------------------------------------- |
| options | { connectionId: string; inputId: string | null; } |
webrtcSetOutputRoute(...)
webrtcSetOutputRoute(options: { connectionId: string; route: OutputRoute; }) => Promise<void>| Param | Type |
| ------------- | ------------------------------------------------------------------------------------- |
| options | { connectionId: string; route: OutputRoute; } |
webrtcGetState(...)
webrtcGetState(options: { connectionId: string; }) => Promise<NativeWebRTCStateResult>| Param | Type |
| ------------- | -------------------------------------- |
| options | { connectionId: string; } |
Returns: Promise<NativeWebRTCStateResult>
webrtcGetDiagnostics(...)
webrtcGetDiagnostics(options: { connectionId: string; }) => Promise<Record<string, unknown>>| Param | Type |
| ------------- | -------------------------------------- |
| options | { connectionId: string; } |
Returns: Promise<Record<string, unknown>>
addListener('micStateChanged', ...)
addListener(eventName: 'micStateChanged', listenerFunc: (event: MicStateChangedEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------------- |
| eventName | 'micStateChanged' |
| listenerFunc | (event: MicStateChangedEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('micPcmChunk', ...)
addListener(eventName: 'micPcmChunk', listenerFunc: (event: MicPcmChunkEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | --------------------------------------------------------------------------------- |
| eventName | 'micPcmChunk' |
| listenerFunc | (event: MicPcmChunkEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('micAudioLevel', ...)
addListener(eventName: 'micAudioLevel', listenerFunc: (event: MicAudioLevelEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------- |
| eventName | 'micAudioLevel' |
| listenerFunc | (event: MicAudioLevelEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('micRouteChanged', ...)
addListener(eventName: 'micRouteChanged', listenerFunc: (event: MicRouteChangedEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------------- |
| eventName | 'micRouteChanged' |
| listenerFunc | (event: MicRouteChangedEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('micInterruption', ...)
addListener(eventName: 'micInterruption', listenerFunc: (event: MicInterruptionEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------------- |
| eventName | 'micInterruption' |
| listenerFunc | (event: MicInterruptionEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('micError', ...)
addListener(eventName: 'micError', listenerFunc: (event: MicErrorEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | --------------------------------------------------------------------------- |
| eventName | 'micError' |
| listenerFunc | (event: MicErrorEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('webrtcStateChanged', ...)
addListener(eventName: 'webrtcStateChanged', listenerFunc: (event: NativeWebRTCStateChangedEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------------------------------- |
| eventName | 'webrtcStateChanged' |
| listenerFunc | (event: NativeWebRTCStateChangedEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('webrtcDataMessage', ...)
addListener(eventName: 'webrtcDataMessage', listenerFunc: (event: NativeWebRTCDataMessageEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | --------------------------------------------------------------------------------------------------------- |
| eventName | 'webrtcDataMessage' |
| listenerFunc | (event: NativeWebRTCDataMessageEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('webrtcTrackStarted', ...)
addListener(eventName: 'webrtcTrackStarted', listenerFunc: (event: NativeWebRTCTrackEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | --------------------------------------------------------------------------------------------- |
| eventName | 'webrtcTrackStarted' |
| listenerFunc | (event: NativeWebRTCTrackEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('webrtcTrackStopped', ...)
addListener(eventName: 'webrtcTrackStopped', listenerFunc: (event: NativeWebRTCTrackEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | --------------------------------------------------------------------------------------------- |
| eventName | 'webrtcTrackStopped' |
| listenerFunc | (event: NativeWebRTCTrackEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('webrtcLocalAudioLevel', ...)
addListener(eventName: 'webrtcLocalAudioLevel', listenerFunc: (event: NativeWebRTCAudioLevelEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------------------- |
| eventName | 'webrtcLocalAudioLevel' |
| listenerFunc | (event: NativeWebRTCAudioLevelEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('webrtcRemoteAudioLevel', ...)
addListener(eventName: 'webrtcRemoteAudioLevel', listenerFunc: (event: NativeWebRTCAudioLevelEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------------------- |
| eventName | 'webrtcRemoteAudioLevel' |
| listenerFunc | (event: NativeWebRTCAudioLevelEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('webrtcError', ...)
addListener(eventName: 'webrtcError', listenerFunc: (event: NativeWebRTCErrorEvent) => void) => Promise<PluginListenerHandle>| Param | Type |
| ------------------ | --------------------------------------------------------------------------------------------- |
| eventName | 'webrtcError' |
| listenerFunc | (event: NativeWebRTCErrorEvent) => void |
Returns: Promise<PluginListenerHandle>
removeAllListeners()
removeAllListeners() => Promise<void>Interfaces
MicDevice
| Prop | Type |
| --------------- | ----------------------------------------------------------------------- |
| id | string |
| label | string |
| type | 'built_in' | 'wired' | 'bluetooth' | 'usb' | 'unknown' |
| isDefault | boolean |
StartCaptureResult
| Prop | Type |
| --------------------------- | ------------------- |
| captureId | string |
| actualInputSampleRate | number |
| actualInputChannels | number |
| chunkMs | number |
StartCaptureOptions
| Prop | Type |
| -------------------------- | --------------------------------------------------- |
| profile | MicProfile |
| mode | SessionMode |
| outputStreams | OutputStream[] |
| chunkMs | number |
| emitAudioLevel | boolean |
| audioLevelIntervalMs | number |
| voiceProcessing | boolean |
| preferredInputId | string |
| outputRoute | OutputRoute |
StopCaptureResult
| Prop | Type |
| ----------------------- | ------------------- |
| captureId | string |
| totalFramesIn | number |
| totalFramesOut16k | number |
| totalFramesOut48k | number |
| durationMs | number |
StopCaptureOptions
| Prop | Type |
| -------------------- | ------------------- |
| captureId | string |
| flushTimeoutMs | number |
NativeWebRTCConnectResult
| Prop | Type |
| ------------------------- | --------------------------------------------------------------- |
| connectionId | string |
| pcId | string |
| selectedInputId | string |
| selectedOutputRoute | OutputRoute |
| state | NativeWebRTCState |
NativeWebRTCConnectOptions
| Prop | Type |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| connectionId | string |
| webrtcRequest | WebRTCRequestInfo |
| iceConfig | { iceServers?: RTCIceServerLike[]; } |
| waitForICEGathering | boolean |
| audioCodec | string | null |
| videoCodec | string | null |
| media | { voiceProcessing?: boolean; startMicEnabled?: boolean; preferredInputId?: string; outputRoute?: OutputRoute; } |
| reconnect | { enabled?: boolean; maxAttempts?: number; backoffMs?: number; } |
WebRTCRequestInfo
| Prop | Type |
| ----------------- | ---------------------------------------------------------------- |
| endpoint | string |
| headers | Record<string, string> |
| requestData | Record<string, unknown> |
| timeoutMs | number |
NativeWebRTCStateResult
| Prop | Type |
| ------------------------ | --------------------------------------------------------------- |
| connectionId | string |
| state | NativeWebRTCState |
| pcId | string |
| iceConnectionState | string |
| signalingState | string |
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
MicStateChangedEvent
| Prop | Type |
| --------------- | -------------------------------------------- |
| captureId | string |
| state | 'idle' | 'running' | 'paused' |
| reason | string |
MicPcmChunkEvent
| Prop | Type |
| ---------------- | ----------------------------------------------------- |
| captureId | string |
| stream | OutputStream |
| sampleRate | 16000 | 48000 |
| channels | 1 |
| frames | number |
| seq | number |
| ptsMs | number |
| dataBase64 | string |
| final | boolean |
MicAudioLevelEvent
| Prop | Type |
| --------------- | -------------------- |
| captureId | string |
| rms | number |
| peak | number |
| dbfs | number |
| vad | boolean |
| ptsMs | number |
MicRouteChangedEvent
| Prop | Type |
| --------------------- | ------------------- |
| captureId | string |
| reason | string |
| selectedInputId | string |
MicInterruptionEvent
| Prop | Type |
| ------------------ | ------------------------------- |
| captureId | string |
| phase | 'began' | 'ended' |
| shouldResume | boolean |
| reason | string |
MicErrorEvent
| Prop | Type |
| ----------------- | -------------------- |
| captureId | string |
| code | string |
| message | string |
| recoverable | boolean |
| nativeCode | string |
NativeWebRTCStateChangedEvent
| Prop | Type |
| ------------------ | --------------------------------------------------------------- |
| connectionId | string |
| state | NativeWebRTCState |
| reason | string |
| pcId | string |
NativeWebRTCDataMessageEvent
| Prop | Type |
| ------------------ | ------------------- |
| connectionId | string |
| data | string |
NativeWebRTCTrackEvent
| Prop | Type |
| ------------------ | ------------------------------------------------ |
| connectionId | string |
| kind | 'audio' | 'video' | 'screenVideo' |
| source | 'remote' | 'local' |
NativeWebRTCAudioLevelEvent
| Prop | Type |
| ------------------ | ------------------- |
| connectionId | string |
| level | number |
NativeWebRTCErrorEvent
| Prop | Type |
| ------------------ | ----------------------------------------------------------------------- |
| connectionId | string |
| code | NativeWebRTCErrorCode |
| message | string |
| recoverable | boolean |
| nativeCode | string |
Type Aliases
MicPermissionState
'prompt' | 'granted' | 'denied'
OutputRoute
'system' | 'speaker' | 'receiver'
MicProfile
'waveform' | 'pipecat'
SessionMode
'measurement' | 'voice_chat'
OutputStream
'pcm16k_s16le' | 'pcm48k_s16le'
Record
Construct a type with a set of properties K of type T
{ [P in K]: T; }
NativeWebRTCState
'idle' | 'initializing' | 'connecting' | 'connected' | 'ready' | 'reconnecting' | 'disconnecting' | 'error'
RTCIceServerLike
{ urls: string | string[]; username?: string; credential?: string; }
NativeWebRTCErrorCode
'E_WEBRTC_UNAVAILABLE' | 'E_PC_CREATE_FAILED' | 'E_NEGOTIATION_FAILED' | 'E_ICE_FAILED' | 'E_DATA_CHANNEL_FAILED' | 'E_ALREADY_RUNNING' | 'E_NOT_RUNNING' | 'E_INVALID_ARGUMENT' | 'E_INTERNAL'
