Hooks
Documentation for useOrgaAI, including return values and usage examples.
useOrgaAI
Access Orga SDK methods and state in your components
Import
import { useOrgaAI } from '@orga-ai/react';
Returns
|
Name |
Type |
Description |
|---|---|---|
|
|
|
Starts a new session with optional configuration. Use to initiate an AI conversation. |
|
|
|
Ends the current session, stopping all media streams and connections. |
|
|
|
Enables the microphone for audio input. |
|
|
|
Disables the microphone, muting audio input. |
|
|
|
Toggles the microphone’s state (on/off). |
|
|
|
Enables the camera for video input. |
|
|
|
Disables the camera, stopping video input. |
|
|
|
Toggles the camera’s state (on/off). |
|
|
|
The current connection state (e.g., "disconnected", "connecting", "connected"). |
|
|
|
The AI’s audio stream, or null if not available. |
|
|
|
The user’s video stream, or null if not available. |
|
|
|
Array of conversation items, including user speech and AI responses. |
|
|
|
Indicates whether the camera is currently enabled. |
|
|
|
Indicates whether the microphone is currently enabled. |
|
|
|
The unique ID of the current conversation, or null if no conversation is active. |
|
|
|
The selected AI model, or default model if not set. |
|
|
|
The selected voice for AI responses, or default voice if not set. |
|
|
|
The sampling temperature for AI responses, or null if not set. |
|
|
|
Custom instructions for the AI, or null if not set. |
|
|
|
Array of enabled modalities (e.g., audio, video). |
|
|
|
Updates session parameters (e.g., model, voice, temperature). |
Usage
const { startSession, endSession, videoStream } = useOrgaAI();
export default function HomeScreen() {
const {
startSession,
endSession,
userVideoStream,
connectionState,
isMicOn,
toggleMic,
toggleCamera,
updateParams,
} = useOrgaAI();
const handleStart = async () => {
await startSession({
onSessionConnected: () => console.log('Connected!'),
});
updateParams({ model: 'orga-1-beta', voice: 'alloy' });
};
return (
<div>
<p>Connection: {connectionState}</p>
<p>Mic: {isMicOn ? 'On' : 'Off'}</p>
<button onClick={toggleMic}>Toggle Mic</button>
<button onClick={handleStart}>Start Session</button>
<button onClick={endSession}>End Session</button>
</div>
);
}