@speechos/react 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * useSpeechOSEvents - Hook for subscribing to SpeechOS events
3
+ *
4
+ * Automatically handles subscription lifecycle tied to component mount/unmount.
5
+ */
6
+ import { type SpeechOSEventMap, type UnsubscribeFn } from "@speechos/core";
7
+ /**
8
+ * Hook to subscribe to SpeechOS events
9
+ *
10
+ * Automatically subscribes on mount and unsubscribes on unmount.
11
+ * The callback is stable - changes to it will update the subscription.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * function TranscriptionListener() {
16
+ * useSpeechOSEvents('transcription:complete', (payload) => {
17
+ * console.log('Transcription received:', payload.text);
18
+ * });
19
+ *
20
+ * useSpeechOSEvents('error', (payload) => {
21
+ * console.error('Error:', payload.message);
22
+ * });
23
+ *
24
+ * return <div>Listening for events...</div>;
25
+ * }
26
+ * ```
27
+ *
28
+ * @param event - The event name to subscribe to
29
+ * @param callback - The callback to invoke when the event fires
30
+ * @returns Cleanup function (automatically called on unmount)
31
+ */
32
+ export declare function useSpeechOSEvents<K extends keyof SpeechOSEventMap>(event: K, callback: (payload: SpeechOSEventMap[K]) => void): UnsubscribeFn;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * useSpeechOSEvents - Hook for subscribing to SpeechOS events
3
+ *
4
+ * Automatically handles subscription lifecycle tied to component mount/unmount.
5
+ */
6
+ import { type SpeechOSEventMap, type UnsubscribeFn } from "@speechos/core";
7
+ /**
8
+ * Hook to subscribe to SpeechOS events
9
+ *
10
+ * Automatically subscribes on mount and unsubscribes on unmount.
11
+ * The callback is stable - changes to it will update the subscription.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * function TranscriptionListener() {
16
+ * useSpeechOSEvents('transcription:complete', (payload) => {
17
+ * console.log('Transcription received:', payload.text);
18
+ * });
19
+ *
20
+ * useSpeechOSEvents('error', (payload) => {
21
+ * console.error('Error:', payload.message);
22
+ * });
23
+ *
24
+ * return <div>Listening for events...</div>;
25
+ * }
26
+ * ```
27
+ *
28
+ * @param event - The event name to subscribe to
29
+ * @param callback - The callback to invoke when the event fires
30
+ * @returns Cleanup function (automatically called on unmount)
31
+ */
32
+ export declare function useSpeechOSEvents<K extends keyof SpeechOSEventMap>(event: K, callback: (payload: SpeechOSEventMap[K]) => void): UnsubscribeFn;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * useSpeechOSState - Hook for accessing just the SpeechOS state
3
+ *
4
+ * A lightweight hook when you only need to read state,
5
+ * not call any API methods.
6
+ */
7
+ import type { SpeechOSState } from "@speechos/core";
8
+ /**
9
+ * Hook to access just the SpeechOS state
10
+ *
11
+ * Use this when you only need to read state values like
12
+ * isConnected, recordingState, etc. without needing the API methods.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * function RecordingIndicator() {
17
+ * const state = useSpeechOSState();
18
+ *
19
+ * return (
20
+ * <div>
21
+ * {state.recordingState === 'recording' && <span>Recording...</span>}
22
+ * {state.isConnected && <span>Connected</span>}
23
+ * </div>
24
+ * );
25
+ * }
26
+ * ```
27
+ *
28
+ * @returns The current SpeechOS state
29
+ */
30
+ export declare function useSpeechOSState(): SpeechOSState;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * useSpeechOSState - Hook for accessing just the SpeechOS state
3
+ *
4
+ * A lightweight hook when you only need to read state,
5
+ * not call any API methods.
6
+ */
7
+ import type { SpeechOSState } from "@speechos/core";
8
+ /**
9
+ * Hook to access just the SpeechOS state
10
+ *
11
+ * Use this when you only need to read state values like
12
+ * isConnected, recordingState, etc. without needing the API methods.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * function RecordingIndicator() {
17
+ * const state = useSpeechOSState();
18
+ *
19
+ * return (
20
+ * <div>
21
+ * {state.recordingState === 'recording' && <span>Recording...</span>}
22
+ * {state.isConnected && <span>Connected</span>}
23
+ * </div>
24
+ * );
25
+ * }
26
+ * ```
27
+ *
28
+ * @returns The current SpeechOS state
29
+ */
30
+ export declare function useSpeechOSState(): SpeechOSState;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * useTranscription - Low-level hook for granular transcription control
3
+ *
4
+ * Provides direct access to the LiveKit connection lifecycle
5
+ * for advanced use cases that need fine-grained control.
6
+ */
7
+ import type { SpeechOSState } from "@speechos/core";
8
+ /**
9
+ * Return type for useTranscription hook
10
+ */
11
+ export interface UseTranscriptionResult {
12
+ /** Connect to LiveKit (establishes WebRTC connection) */
13
+ connect: () => Promise<void>;
14
+ /** Wait until the agent is ready to receive audio */
15
+ waitUntilReady: () => Promise<void>;
16
+ /** Enable microphone (start capturing audio) */
17
+ enableMicrophone: () => Promise<void>;
18
+ /** Stop recording and get the transcript */
19
+ getTranscript: () => Promise<string>;
20
+ /** Stop recording and get edited text */
21
+ getEdit: (originalText: string) => Promise<string>;
22
+ /** Disconnect from LiveKit */
23
+ disconnect: () => Promise<void>;
24
+ /** Cancel any ongoing operation */
25
+ cancel: () => Promise<void>;
26
+ /** Current connection state */
27
+ isConnected: boolean;
28
+ /** Current microphone state */
29
+ isMicEnabled: boolean;
30
+ /** Current recording state */
31
+ recordingState: SpeechOSState["recordingState"];
32
+ }
33
+ /**
34
+ * Low-level hook for granular transcription control
35
+ *
36
+ * Use this when you need fine-grained control over the LiveKit
37
+ * connection lifecycle. For most use cases, prefer useDictation()
38
+ * or useEdit() which provide simpler interfaces.
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * function CustomVoiceUI() {
43
+ * const {
44
+ * connect,
45
+ * waitUntilReady,
46
+ * enableMicrophone,
47
+ * getTranscript,
48
+ * disconnect,
49
+ * isConnected,
50
+ * isMicEnabled,
51
+ * recordingState,
52
+ * } = useTranscription();
53
+ *
54
+ * const handleRecord = async () => {
55
+ * // Step 1: Connect to LiveKit
56
+ * await connect();
57
+ *
58
+ * // Step 2: Wait for agent to be ready
59
+ * await waitUntilReady();
60
+ *
61
+ * // Step 3: Enable microphone
62
+ * await enableMicrophone();
63
+ *
64
+ * // ... user speaks ...
65
+ *
66
+ * // Step 4: Get transcript
67
+ * const text = await getTranscript();
68
+ * console.log('Transcribed:', text);
69
+ *
70
+ * // Step 5: Cleanup
71
+ * await disconnect();
72
+ * };
73
+ *
74
+ * return (
75
+ * <div>
76
+ * <p>Connected: {isConnected ? 'Yes' : 'No'}</p>
77
+ * <p>Mic: {isMicEnabled ? 'On' : 'Off'}</p>
78
+ * <p>State: {recordingState}</p>
79
+ * <button onClick={handleRecord}>Record</button>
80
+ * </div>
81
+ * );
82
+ * }
83
+ * ```
84
+ *
85
+ * @returns Low-level transcription controls and state
86
+ */
87
+ export declare function useTranscription(): UseTranscriptionResult;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * useTranscription - Low-level hook for granular transcription control
3
+ *
4
+ * Provides direct access to the LiveKit connection lifecycle
5
+ * for advanced use cases that need fine-grained control.
6
+ */
7
+ import type { SpeechOSState } from "@speechos/core";
8
+ /**
9
+ * Return type for useTranscription hook
10
+ */
11
+ export interface UseTranscriptionResult {
12
+ /** Connect to LiveKit (establishes WebRTC connection) */
13
+ connect: () => Promise<void>;
14
+ /** Wait until the agent is ready to receive audio */
15
+ waitUntilReady: () => Promise<void>;
16
+ /** Enable microphone (start capturing audio) */
17
+ enableMicrophone: () => Promise<void>;
18
+ /** Stop recording and get the transcript */
19
+ getTranscript: () => Promise<string>;
20
+ /** Stop recording and get edited text */
21
+ getEdit: (originalText: string) => Promise<string>;
22
+ /** Disconnect from LiveKit */
23
+ disconnect: () => Promise<void>;
24
+ /** Cancel any ongoing operation */
25
+ cancel: () => Promise<void>;
26
+ /** Current connection state */
27
+ isConnected: boolean;
28
+ /** Current microphone state */
29
+ isMicEnabled: boolean;
30
+ /** Current recording state */
31
+ recordingState: SpeechOSState["recordingState"];
32
+ }
33
+ /**
34
+ * Low-level hook for granular transcription control
35
+ *
36
+ * Use this when you need fine-grained control over the LiveKit
37
+ * connection lifecycle. For most use cases, prefer useDictation()
38
+ * or useEdit() which provide simpler interfaces.
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * function CustomVoiceUI() {
43
+ * const {
44
+ * connect,
45
+ * waitUntilReady,
46
+ * enableMicrophone,
47
+ * getTranscript,
48
+ * disconnect,
49
+ * isConnected,
50
+ * isMicEnabled,
51
+ * recordingState,
52
+ * } = useTranscription();
53
+ *
54
+ * const handleRecord = async () => {
55
+ * // Step 1: Connect to LiveKit
56
+ * await connect();
57
+ *
58
+ * // Step 2: Wait for agent to be ready
59
+ * await waitUntilReady();
60
+ *
61
+ * // Step 3: Enable microphone
62
+ * await enableMicrophone();
63
+ *
64
+ * // ... user speaks ...
65
+ *
66
+ * // Step 4: Get transcript
67
+ * const text = await getTranscript();
68
+ * console.log('Transcribed:', text);
69
+ *
70
+ * // Step 5: Cleanup
71
+ * await disconnect();
72
+ * };
73
+ *
74
+ * return (
75
+ * <div>
76
+ * <p>Connected: {isConnected ? 'Yes' : 'No'}</p>
77
+ * <p>Mic: {isMicEnabled ? 'On' : 'Off'}</p>
78
+ * <p>State: {recordingState}</p>
79
+ * <button onClick={handleRecord}>Record</button>
80
+ * </div>
81
+ * );
82
+ * }
83
+ * ```
84
+ *
85
+ * @returns Low-level transcription controls and state
86
+ */
87
+ export declare function useTranscription(): UseTranscriptionResult;