UNPKG

@speechmatics/flow-client-react

Version:

React hooks for interacting with the Speechmatics Flow API

33 lines (27 loc) 1.61 kB
import { StartConversationMessage, FlowClientEventMap, FlowClient, FlowClientOptions } from '@speechmatics/flow-client'; export * from '@speechmatics/flow-client'; import { TypedEventListenerOrEventListenerObject } from 'typescript-event-target'; import * as react from 'react'; import * as react_jsx_runtime from 'react/jsx-runtime'; declare function useFlow(): { startConversation: (jwt: string, { config, audioFormat, }: { config: StartConversationMessage["conversation_config"]; audioFormat?: StartConversationMessage["audio_format"]; }) => Promise<void>; endConversation: () => void; sendAudio: (pcm16Data: ArrayBufferLike) => void; socketState: "connecting" | "open" | "closing" | "closed" | undefined; sessionId: string | undefined; }; declare function useFlowEventListener<E extends keyof FlowClientEventMap>(message: E, cb: TypedEventListenerOrEventListenerObject<FlowClientEventMap, E>): void; declare function useClientEventListener<K extends keyof FlowClientEventMap>(client: FlowClient, eventType: K, cb: TypedEventListenerOrEventListenerObject<FlowClientEventMap, K>): void; type IFlowClientContext = { client: FlowClient; socketState: FlowClient['socketState']; sessionId?: string; }; declare const FlowContext: react.Context<IFlowClientContext | null>; declare function FlowProvider({ server, children, ...options }: React.PropsWithChildren<{ server?: string; } & FlowClientOptions>): react_jsx_runtime.JSX.Element; export { FlowContext, FlowProvider, type IFlowClientContext, useClientEventListener, useFlow, useFlowEventListener };