@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.
- package/dist/components/SpeechOSWidget.d.cts +101 -0
- package/dist/components/SpeechOSWidget.d.ts +101 -0
- package/dist/components/index.d.cts +6 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/context.d.cts +63 -0
- package/dist/context.d.ts +63 -0
- package/dist/hooks/index.d.cts +11 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/useDictation.d.cts +51 -0
- package/dist/hooks/useDictation.d.ts +51 -0
- package/dist/hooks/useEdit.d.cts +63 -0
- package/dist/hooks/useEdit.d.ts +63 -0
- package/dist/hooks/useSpeechOS.d.cts +35 -0
- package/dist/hooks/useSpeechOS.d.ts +35 -0
- package/dist/hooks/useSpeechOSEvents.d.cts +32 -0
- package/dist/hooks/useSpeechOSEvents.d.ts +32 -0
- package/dist/hooks/useSpeechOSState.d.cts +30 -0
- package/dist/hooks/useSpeechOSState.d.ts +30 -0
- package/dist/hooks/useTranscription.d.cts +87 -0
- package/dist/hooks/useTranscription.d.ts +87 -0
- package/dist/index.cjs +550 -0
- package/dist/index.d.cts +59 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +517 -0
- package/package.json +73 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SpeechOSWidget - React wrapper for the Lit Web Component widget
|
|
3
|
+
*
|
|
4
|
+
* Mounts the existing <speechos-widget> Web Component and forwards
|
|
5
|
+
* React props as attributes and event handlers.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Props for SpeechOSWidget
|
|
9
|
+
*/
|
|
10
|
+
export interface SpeechOSWidgetProps {
|
|
11
|
+
/**
|
|
12
|
+
* API key for SpeechOS authentication.
|
|
13
|
+
* If not provided, must be set via SpeechOSProvider config.
|
|
14
|
+
*/
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Optional user identifier for tracking
|
|
18
|
+
*/
|
|
19
|
+
userId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Position of the widget on screen
|
|
22
|
+
* @default 'bottom-center'
|
|
23
|
+
*/
|
|
24
|
+
position?: "bottom-center" | "bottom-right" | "bottom-left";
|
|
25
|
+
/**
|
|
26
|
+
* Backend host URL (for development/testing)
|
|
27
|
+
*/
|
|
28
|
+
host?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Custom z-index for the widget overlay
|
|
31
|
+
*/
|
|
32
|
+
zIndex?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Enable debug logging
|
|
35
|
+
*/
|
|
36
|
+
debug?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Callback when transcription is completed and inserted
|
|
39
|
+
*/
|
|
40
|
+
onTranscription?: (text: string, element: HTMLElement) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Callback when edit is completed and applied
|
|
43
|
+
*/
|
|
44
|
+
onEdit?: (editedText: string, originalText: string, element: HTMLElement) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Callback when an error occurs
|
|
47
|
+
*/
|
|
48
|
+
onError?: (error: {
|
|
49
|
+
code: string;
|
|
50
|
+
message: string;
|
|
51
|
+
source: string;
|
|
52
|
+
}) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Callback when widget becomes visible
|
|
55
|
+
*/
|
|
56
|
+
onShow?: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Callback when widget is hidden
|
|
59
|
+
*/
|
|
60
|
+
onHide?: () => void;
|
|
61
|
+
/**
|
|
62
|
+
* Additional class name for the container
|
|
63
|
+
*/
|
|
64
|
+
className?: string;
|
|
65
|
+
}
|
|
66
|
+
declare global {
|
|
67
|
+
namespace JSX {
|
|
68
|
+
interface IntrinsicElements {
|
|
69
|
+
"speechos-widget": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* SpeechOSWidget - React wrapper for the SpeechOS Web Component
|
|
75
|
+
*
|
|
76
|
+
* This component mounts the existing <speechos-widget> Lit Web Component
|
|
77
|
+
* and bridges React props to the Web Component's attributes and events.
|
|
78
|
+
*
|
|
79
|
+
* Note: Requires @speechos/client to be installed and imported somewhere
|
|
80
|
+
* in your app to register the Web Component.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* import { SpeechOSProvider, SpeechOSWidget } from '@speechos/react';
|
|
85
|
+
* import '@speechos/client'; // Registers the Web Component
|
|
86
|
+
*
|
|
87
|
+
* function App() {
|
|
88
|
+
* return (
|
|
89
|
+
* <SpeechOSProvider>
|
|
90
|
+
* <MyForm />
|
|
91
|
+
* <SpeechOSWidget
|
|
92
|
+
* apiKey="your-key"
|
|
93
|
+
* onTranscription={(text) => console.log('Transcribed:', text)}
|
|
94
|
+
* onError={(error) => console.error(error)}
|
|
95
|
+
* />
|
|
96
|
+
* </SpeechOSProvider>
|
|
97
|
+
* );
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function SpeechOSWidget({ apiKey, userId, position, host, zIndex, debug, onTranscription, onEdit, onError, onShow, onHide, className, }: SpeechOSWidgetProps): React.ReactNode;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SpeechOSWidget - React wrapper for the Lit Web Component widget
|
|
3
|
+
*
|
|
4
|
+
* Mounts the existing <speechos-widget> Web Component and forwards
|
|
5
|
+
* React props as attributes and event handlers.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Props for SpeechOSWidget
|
|
9
|
+
*/
|
|
10
|
+
export interface SpeechOSWidgetProps {
|
|
11
|
+
/**
|
|
12
|
+
* API key for SpeechOS authentication.
|
|
13
|
+
* If not provided, must be set via SpeechOSProvider config.
|
|
14
|
+
*/
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Optional user identifier for tracking
|
|
18
|
+
*/
|
|
19
|
+
userId?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Position of the widget on screen
|
|
22
|
+
* @default 'bottom-center'
|
|
23
|
+
*/
|
|
24
|
+
position?: "bottom-center" | "bottom-right" | "bottom-left";
|
|
25
|
+
/**
|
|
26
|
+
* Backend host URL (for development/testing)
|
|
27
|
+
*/
|
|
28
|
+
host?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Custom z-index for the widget overlay
|
|
31
|
+
*/
|
|
32
|
+
zIndex?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Enable debug logging
|
|
35
|
+
*/
|
|
36
|
+
debug?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Callback when transcription is completed and inserted
|
|
39
|
+
*/
|
|
40
|
+
onTranscription?: (text: string, element: HTMLElement) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Callback when edit is completed and applied
|
|
43
|
+
*/
|
|
44
|
+
onEdit?: (editedText: string, originalText: string, element: HTMLElement) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Callback when an error occurs
|
|
47
|
+
*/
|
|
48
|
+
onError?: (error: {
|
|
49
|
+
code: string;
|
|
50
|
+
message: string;
|
|
51
|
+
source: string;
|
|
52
|
+
}) => void;
|
|
53
|
+
/**
|
|
54
|
+
* Callback when widget becomes visible
|
|
55
|
+
*/
|
|
56
|
+
onShow?: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Callback when widget is hidden
|
|
59
|
+
*/
|
|
60
|
+
onHide?: () => void;
|
|
61
|
+
/**
|
|
62
|
+
* Additional class name for the container
|
|
63
|
+
*/
|
|
64
|
+
className?: string;
|
|
65
|
+
}
|
|
66
|
+
declare global {
|
|
67
|
+
namespace JSX {
|
|
68
|
+
interface IntrinsicElements {
|
|
69
|
+
"speechos-widget": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* SpeechOSWidget - React wrapper for the SpeechOS Web Component
|
|
75
|
+
*
|
|
76
|
+
* This component mounts the existing <speechos-widget> Lit Web Component
|
|
77
|
+
* and bridges React props to the Web Component's attributes and events.
|
|
78
|
+
*
|
|
79
|
+
* Note: Requires @speechos/client to be installed and imported somewhere
|
|
80
|
+
* in your app to register the Web Component.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* import { SpeechOSProvider, SpeechOSWidget } from '@speechos/react';
|
|
85
|
+
* import '@speechos/client'; // Registers the Web Component
|
|
86
|
+
*
|
|
87
|
+
* function App() {
|
|
88
|
+
* return (
|
|
89
|
+
* <SpeechOSProvider>
|
|
90
|
+
* <MyForm />
|
|
91
|
+
* <SpeechOSWidget
|
|
92
|
+
* apiKey="your-key"
|
|
93
|
+
* onTranscription={(text) => console.log('Transcribed:', text)}
|
|
94
|
+
* onError={(error) => console.error(error)}
|
|
95
|
+
* />
|
|
96
|
+
* </SpeechOSProvider>
|
|
97
|
+
* );
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function SpeechOSWidget({ apiKey, userId, position, host, zIndex, debug, onTranscription, onEdit, onError, onShow, onHide, className, }: SpeechOSWidgetProps): React.ReactNode;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SpeechOS React Context
|
|
3
|
+
*
|
|
4
|
+
* Provides React integration for SpeechOS SDK.
|
|
5
|
+
* Uses useSyncExternalStore for efficient state synchronization.
|
|
6
|
+
*/
|
|
7
|
+
import React, { type ReactNode } from "react";
|
|
8
|
+
import { type SpeechOSConfig, type SpeechOSState, type SpeechOSEventMap, type UnsubscribeFn } from "@speechos/core";
|
|
9
|
+
/**
|
|
10
|
+
* Context value exposed by SpeechOSProvider
|
|
11
|
+
*/
|
|
12
|
+
export interface SpeechOSContextValue {
|
|
13
|
+
state: SpeechOSState;
|
|
14
|
+
isInitialized: boolean;
|
|
15
|
+
init: (config: SpeechOSConfig) => void;
|
|
16
|
+
dictate: () => Promise<string>;
|
|
17
|
+
stopDictation: () => Promise<string>;
|
|
18
|
+
edit: (text: string) => Promise<string>;
|
|
19
|
+
stopEdit: () => Promise<string>;
|
|
20
|
+
cancel: () => Promise<void>;
|
|
21
|
+
connect: () => Promise<void>;
|
|
22
|
+
disconnect: () => Promise<void>;
|
|
23
|
+
enableMicrophone: () => Promise<void>;
|
|
24
|
+
waitUntilReady: () => Promise<void>;
|
|
25
|
+
stopAndGetTranscript: () => Promise<string>;
|
|
26
|
+
stopAndEdit: (originalText: string) => Promise<string>;
|
|
27
|
+
on: <K extends keyof SpeechOSEventMap>(event: K, callback: (payload: SpeechOSEventMap[K]) => void) => UnsubscribeFn;
|
|
28
|
+
off: <K extends keyof SpeechOSEventMap>(event: K, callback: (payload: SpeechOSEventMap[K]) => void) => void;
|
|
29
|
+
}
|
|
30
|
+
declare const SpeechOSContext: React.Context<SpeechOSContextValue | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Props for SpeechOSProvider
|
|
33
|
+
*/
|
|
34
|
+
export interface SpeechOSProviderProps {
|
|
35
|
+
/**
|
|
36
|
+
* Optional initial configuration.
|
|
37
|
+
* If provided, SDK will be initialized automatically.
|
|
38
|
+
*/
|
|
39
|
+
config?: SpeechOSConfig;
|
|
40
|
+
children: ReactNode;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* SpeechOS Provider component
|
|
44
|
+
*
|
|
45
|
+
* Wraps your app to provide SpeechOS context to all child components.
|
|
46
|
+
* Can optionally auto-initialize with a config.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* <SpeechOSProvider config={{ apiKey: 'your-key' }}>
|
|
51
|
+
* <App />
|
|
52
|
+
* </SpeechOSProvider>
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function SpeechOSProvider({ config, children, }: SpeechOSProviderProps): ReactNode;
|
|
56
|
+
/**
|
|
57
|
+
* Hook to access the SpeechOS context
|
|
58
|
+
*
|
|
59
|
+
* @throws Error if used outside of SpeechOSProvider
|
|
60
|
+
* @returns The SpeechOS context value
|
|
61
|
+
*/
|
|
62
|
+
export declare function useSpeechOSContext(): SpeechOSContextValue;
|
|
63
|
+
export { SpeechOSContext };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SpeechOS React Context
|
|
3
|
+
*
|
|
4
|
+
* Provides React integration for SpeechOS SDK.
|
|
5
|
+
* Uses useSyncExternalStore for efficient state synchronization.
|
|
6
|
+
*/
|
|
7
|
+
import React, { type ReactNode } from "react";
|
|
8
|
+
import { type SpeechOSConfig, type SpeechOSState, type SpeechOSEventMap, type UnsubscribeFn } from "@speechos/core";
|
|
9
|
+
/**
|
|
10
|
+
* Context value exposed by SpeechOSProvider
|
|
11
|
+
*/
|
|
12
|
+
export interface SpeechOSContextValue {
|
|
13
|
+
state: SpeechOSState;
|
|
14
|
+
isInitialized: boolean;
|
|
15
|
+
init: (config: SpeechOSConfig) => void;
|
|
16
|
+
dictate: () => Promise<string>;
|
|
17
|
+
stopDictation: () => Promise<string>;
|
|
18
|
+
edit: (text: string) => Promise<string>;
|
|
19
|
+
stopEdit: () => Promise<string>;
|
|
20
|
+
cancel: () => Promise<void>;
|
|
21
|
+
connect: () => Promise<void>;
|
|
22
|
+
disconnect: () => Promise<void>;
|
|
23
|
+
enableMicrophone: () => Promise<void>;
|
|
24
|
+
waitUntilReady: () => Promise<void>;
|
|
25
|
+
stopAndGetTranscript: () => Promise<string>;
|
|
26
|
+
stopAndEdit: (originalText: string) => Promise<string>;
|
|
27
|
+
on: <K extends keyof SpeechOSEventMap>(event: K, callback: (payload: SpeechOSEventMap[K]) => void) => UnsubscribeFn;
|
|
28
|
+
off: <K extends keyof SpeechOSEventMap>(event: K, callback: (payload: SpeechOSEventMap[K]) => void) => void;
|
|
29
|
+
}
|
|
30
|
+
declare const SpeechOSContext: React.Context<SpeechOSContextValue | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Props for SpeechOSProvider
|
|
33
|
+
*/
|
|
34
|
+
export interface SpeechOSProviderProps {
|
|
35
|
+
/**
|
|
36
|
+
* Optional initial configuration.
|
|
37
|
+
* If provided, SDK will be initialized automatically.
|
|
38
|
+
*/
|
|
39
|
+
config?: SpeechOSConfig;
|
|
40
|
+
children: ReactNode;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* SpeechOS Provider component
|
|
44
|
+
*
|
|
45
|
+
* Wraps your app to provide SpeechOS context to all child components.
|
|
46
|
+
* Can optionally auto-initialize with a config.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* <SpeechOSProvider config={{ apiKey: 'your-key' }}>
|
|
51
|
+
* <App />
|
|
52
|
+
* </SpeechOSProvider>
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function SpeechOSProvider({ config, children, }: SpeechOSProviderProps): ReactNode;
|
|
56
|
+
/**
|
|
57
|
+
* Hook to access the SpeechOS context
|
|
58
|
+
*
|
|
59
|
+
* @throws Error if used outside of SpeechOSProvider
|
|
60
|
+
* @returns The SpeechOS context value
|
|
61
|
+
*/
|
|
62
|
+
export declare function useSpeechOSContext(): SpeechOSContextValue;
|
|
63
|
+
export { SpeechOSContext };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @speechos/react hooks
|
|
3
|
+
*
|
|
4
|
+
* React hooks for integrating SpeechOS into your application.
|
|
5
|
+
*/
|
|
6
|
+
export { useSpeechOS } from "./useSpeechOS.js";
|
|
7
|
+
export { useSpeechOSState } from "./useSpeechOSState.js";
|
|
8
|
+
export { useSpeechOSEvents } from "./useSpeechOSEvents.js";
|
|
9
|
+
export { useDictation, type UseDictationResult } from "./useDictation.js";
|
|
10
|
+
export { useEdit, type UseEditResult } from "./useEdit.js";
|
|
11
|
+
export { useTranscription, type UseTranscriptionResult } from "./useTranscription.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @speechos/react hooks
|
|
3
|
+
*
|
|
4
|
+
* React hooks for integrating SpeechOS into your application.
|
|
5
|
+
*/
|
|
6
|
+
export { useSpeechOS } from "./useSpeechOS.js";
|
|
7
|
+
export { useSpeechOSState } from "./useSpeechOSState.js";
|
|
8
|
+
export { useSpeechOSEvents } from "./useSpeechOSEvents.js";
|
|
9
|
+
export { useDictation, type UseDictationResult } from "./useDictation.js";
|
|
10
|
+
export { useEdit, type UseEditResult } from "./useEdit.js";
|
|
11
|
+
export { useTranscription, type UseTranscriptionResult } from "./useTranscription.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useDictation - Simplified hook for dictation workflows
|
|
3
|
+
*
|
|
4
|
+
* Provides a simple start/stop interface for voice-to-text dictation.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Return type for useDictation hook
|
|
8
|
+
*/
|
|
9
|
+
export interface UseDictationResult {
|
|
10
|
+
/** Start dictation - begins recording */
|
|
11
|
+
start: () => Promise<void>;
|
|
12
|
+
/** Stop dictation - ends recording and returns transcript */
|
|
13
|
+
stop: () => Promise<string>;
|
|
14
|
+
/** Whether currently recording */
|
|
15
|
+
isRecording: boolean;
|
|
16
|
+
/** Whether processing the recording */
|
|
17
|
+
isProcessing: boolean;
|
|
18
|
+
/** The last transcribed text (null if none yet) */
|
|
19
|
+
transcript: string | null;
|
|
20
|
+
/** Any error that occurred */
|
|
21
|
+
error: string | null;
|
|
22
|
+
/** Clear the transcript and error state */
|
|
23
|
+
clear: () => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Simplified hook for dictation workflows
|
|
27
|
+
*
|
|
28
|
+
* Provides an easy-to-use interface for voice-to-text dictation
|
|
29
|
+
* with automatic state management.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* function VoiceInput() {
|
|
34
|
+
* const { start, stop, isRecording, isProcessing, transcript, error } = useDictation();
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <div>
|
|
38
|
+
* <button onClick={isRecording ? stop : start} disabled={isProcessing}>
|
|
39
|
+
* {isRecording ? 'Stop' : 'Start'} Recording
|
|
40
|
+
* </button>
|
|
41
|
+
* {isProcessing && <span>Processing...</span>}
|
|
42
|
+
* {transcript && <p>You said: {transcript}</p>}
|
|
43
|
+
* {error && <p style={{ color: 'red' }}>{error}</p>}
|
|
44
|
+
* </div>
|
|
45
|
+
* );
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @returns Dictation controls and state
|
|
50
|
+
*/
|
|
51
|
+
export declare function useDictation(): UseDictationResult;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useDictation - Simplified hook for dictation workflows
|
|
3
|
+
*
|
|
4
|
+
* Provides a simple start/stop interface for voice-to-text dictation.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Return type for useDictation hook
|
|
8
|
+
*/
|
|
9
|
+
export interface UseDictationResult {
|
|
10
|
+
/** Start dictation - begins recording */
|
|
11
|
+
start: () => Promise<void>;
|
|
12
|
+
/** Stop dictation - ends recording and returns transcript */
|
|
13
|
+
stop: () => Promise<string>;
|
|
14
|
+
/** Whether currently recording */
|
|
15
|
+
isRecording: boolean;
|
|
16
|
+
/** Whether processing the recording */
|
|
17
|
+
isProcessing: boolean;
|
|
18
|
+
/** The last transcribed text (null if none yet) */
|
|
19
|
+
transcript: string | null;
|
|
20
|
+
/** Any error that occurred */
|
|
21
|
+
error: string | null;
|
|
22
|
+
/** Clear the transcript and error state */
|
|
23
|
+
clear: () => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Simplified hook for dictation workflows
|
|
27
|
+
*
|
|
28
|
+
* Provides an easy-to-use interface for voice-to-text dictation
|
|
29
|
+
* with automatic state management.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* function VoiceInput() {
|
|
34
|
+
* const { start, stop, isRecording, isProcessing, transcript, error } = useDictation();
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <div>
|
|
38
|
+
* <button onClick={isRecording ? stop : start} disabled={isProcessing}>
|
|
39
|
+
* {isRecording ? 'Stop' : 'Start'} Recording
|
|
40
|
+
* </button>
|
|
41
|
+
* {isProcessing && <span>Processing...</span>}
|
|
42
|
+
* {transcript && <p>You said: {transcript}</p>}
|
|
43
|
+
* {error && <p style={{ color: 'red' }}>{error}</p>}
|
|
44
|
+
* </div>
|
|
45
|
+
* );
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @returns Dictation controls and state
|
|
50
|
+
*/
|
|
51
|
+
export declare function useDictation(): UseDictationResult;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useEdit - Simplified hook for voice editing workflows
|
|
3
|
+
*
|
|
4
|
+
* Provides a simple start/stop interface for voice-based text editing.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Return type for useEdit hook
|
|
8
|
+
*/
|
|
9
|
+
export interface UseEditResult {
|
|
10
|
+
/** Start edit - begins recording voice instructions */
|
|
11
|
+
start: (textToEdit: string) => Promise<void>;
|
|
12
|
+
/** Stop edit - ends recording and returns edited text */
|
|
13
|
+
stop: () => Promise<string>;
|
|
14
|
+
/** Whether currently recording */
|
|
15
|
+
isEditing: boolean;
|
|
16
|
+
/** Whether processing the edit */
|
|
17
|
+
isProcessing: boolean;
|
|
18
|
+
/** The original text being edited */
|
|
19
|
+
originalText: string | null;
|
|
20
|
+
/** The edited result (null if none yet) */
|
|
21
|
+
result: string | null;
|
|
22
|
+
/** Any error that occurred */
|
|
23
|
+
error: string | null;
|
|
24
|
+
/** Clear the result and error state */
|
|
25
|
+
clear: () => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Simplified hook for voice editing workflows
|
|
29
|
+
*
|
|
30
|
+
* Provides an easy-to-use interface for voice-based text editing
|
|
31
|
+
* with automatic state management.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* function TextEditor() {
|
|
36
|
+
* const [text, setText] = useState('Hello world');
|
|
37
|
+
* const { start, stop, isEditing, isProcessing, result, error } = useEdit();
|
|
38
|
+
*
|
|
39
|
+
* const handleEdit = async () => {
|
|
40
|
+
* await start(text);
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* const handleStop = async () => {
|
|
44
|
+
* const edited = await stop();
|
|
45
|
+
* setText(edited);
|
|
46
|
+
* };
|
|
47
|
+
*
|
|
48
|
+
* return (
|
|
49
|
+
* <div>
|
|
50
|
+
* <textarea value={text} onChange={(e) => setText(e.target.value)} />
|
|
51
|
+
* <button onClick={isEditing ? handleStop : handleEdit} disabled={isProcessing}>
|
|
52
|
+
* {isEditing ? 'Apply Edit' : 'Edit with Voice'}
|
|
53
|
+
* </button>
|
|
54
|
+
* {isProcessing && <span>Processing...</span>}
|
|
55
|
+
* {error && <p style={{ color: 'red' }}>{error}</p>}
|
|
56
|
+
* </div>
|
|
57
|
+
* );
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @returns Edit controls and state
|
|
62
|
+
*/
|
|
63
|
+
export declare function useEdit(): UseEditResult;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useEdit - Simplified hook for voice editing workflows
|
|
3
|
+
*
|
|
4
|
+
* Provides a simple start/stop interface for voice-based text editing.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Return type for useEdit hook
|
|
8
|
+
*/
|
|
9
|
+
export interface UseEditResult {
|
|
10
|
+
/** Start edit - begins recording voice instructions */
|
|
11
|
+
start: (textToEdit: string) => Promise<void>;
|
|
12
|
+
/** Stop edit - ends recording and returns edited text */
|
|
13
|
+
stop: () => Promise<string>;
|
|
14
|
+
/** Whether currently recording */
|
|
15
|
+
isEditing: boolean;
|
|
16
|
+
/** Whether processing the edit */
|
|
17
|
+
isProcessing: boolean;
|
|
18
|
+
/** The original text being edited */
|
|
19
|
+
originalText: string | null;
|
|
20
|
+
/** The edited result (null if none yet) */
|
|
21
|
+
result: string | null;
|
|
22
|
+
/** Any error that occurred */
|
|
23
|
+
error: string | null;
|
|
24
|
+
/** Clear the result and error state */
|
|
25
|
+
clear: () => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Simplified hook for voice editing workflows
|
|
29
|
+
*
|
|
30
|
+
* Provides an easy-to-use interface for voice-based text editing
|
|
31
|
+
* with automatic state management.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* function TextEditor() {
|
|
36
|
+
* const [text, setText] = useState('Hello world');
|
|
37
|
+
* const { start, stop, isEditing, isProcessing, result, error } = useEdit();
|
|
38
|
+
*
|
|
39
|
+
* const handleEdit = async () => {
|
|
40
|
+
* await start(text);
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* const handleStop = async () => {
|
|
44
|
+
* const edited = await stop();
|
|
45
|
+
* setText(edited);
|
|
46
|
+
* };
|
|
47
|
+
*
|
|
48
|
+
* return (
|
|
49
|
+
* <div>
|
|
50
|
+
* <textarea value={text} onChange={(e) => setText(e.target.value)} />
|
|
51
|
+
* <button onClick={isEditing ? handleStop : handleEdit} disabled={isProcessing}>
|
|
52
|
+
* {isEditing ? 'Apply Edit' : 'Edit with Voice'}
|
|
53
|
+
* </button>
|
|
54
|
+
* {isProcessing && <span>Processing...</span>}
|
|
55
|
+
* {error && <p style={{ color: 'red' }}>{error}</p>}
|
|
56
|
+
* </div>
|
|
57
|
+
* );
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @returns Edit controls and state
|
|
62
|
+
*/
|
|
63
|
+
export declare function useEdit(): UseEditResult;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSpeechOS - Main hook for full SpeechOS context access
|
|
3
|
+
*
|
|
4
|
+
* Provides access to all SpeechOS functionality including state,
|
|
5
|
+
* high-level API (dictate, edit), and low-level API (connect, enableMicrophone).
|
|
6
|
+
*/
|
|
7
|
+
import { type SpeechOSContextValue } from "../context.js";
|
|
8
|
+
/**
|
|
9
|
+
* Main hook for accessing the full SpeechOS context
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* function MyComponent() {
|
|
14
|
+
* const { state, dictate, cancel, connect, enableMicrophone } = useSpeechOS();
|
|
15
|
+
*
|
|
16
|
+
* // High-level usage
|
|
17
|
+
* const handleDictate = async () => {
|
|
18
|
+
* const text = await dictate();
|
|
19
|
+
* console.log('Transcribed:', text);
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* // Low-level usage
|
|
23
|
+
* const handleCustomFlow = async () => {
|
|
24
|
+
* await connect();
|
|
25
|
+
* await waitUntilReady();
|
|
26
|
+
* await enableMicrophone();
|
|
27
|
+
* // ... custom logic
|
|
28
|
+
* const text = await stopAndGetTranscript();
|
|
29
|
+
* };
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @returns The full SpeechOS context value
|
|
34
|
+
*/
|
|
35
|
+
export declare function useSpeechOS(): SpeechOSContextValue;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSpeechOS - Main hook for full SpeechOS context access
|
|
3
|
+
*
|
|
4
|
+
* Provides access to all SpeechOS functionality including state,
|
|
5
|
+
* high-level API (dictate, edit), and low-level API (connect, enableMicrophone).
|
|
6
|
+
*/
|
|
7
|
+
import { type SpeechOSContextValue } from "../context.js";
|
|
8
|
+
/**
|
|
9
|
+
* Main hook for accessing the full SpeechOS context
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* function MyComponent() {
|
|
14
|
+
* const { state, dictate, cancel, connect, enableMicrophone } = useSpeechOS();
|
|
15
|
+
*
|
|
16
|
+
* // High-level usage
|
|
17
|
+
* const handleDictate = async () => {
|
|
18
|
+
* const text = await dictate();
|
|
19
|
+
* console.log('Transcribed:', text);
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* // Low-level usage
|
|
23
|
+
* const handleCustomFlow = async () => {
|
|
24
|
+
* await connect();
|
|
25
|
+
* await waitUntilReady();
|
|
26
|
+
* await enableMicrophone();
|
|
27
|
+
* // ... custom logic
|
|
28
|
+
* const text = await stopAndGetTranscript();
|
|
29
|
+
* };
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @returns The full SpeechOS context value
|
|
34
|
+
*/
|
|
35
|
+
export declare function useSpeechOS(): SpeechOSContextValue;
|