Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ground-voice-in-fast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@roomote/web": patch
---

Route every voice utterance through Fast so product answers use the Session's tools, context, and safeguards instead of unverified direct voice output.
6 changes: 3 additions & 3 deletions apps/docs/voice.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ and receives only the negotiated session answer; it never receives the API key.
confirms the call is open; a falling tone marks the end. A **Call started**
marker appears in the Session.
3. Talk to Roomote the way you would on a phone call. It acknowledges each
request in a few words, hands the work to the Fast Session, and reports the
result out loud when it lands. Greetings, thanks, and small talk are
answered directly without starting Fast work.
utterance in a few words, hands it to the Fast Session, and reports the
response out loud when it lands. Every utterance is sent to the Fast Session,
where the selected model, tools, context, and safeguards handle the response.
4. Speak at any time to interrupt. Roomote keeps listening while it speaks,
and follow-ups go back through the same Fast Session. You can also type in
the composer during the call.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,6 @@ export function FastSessionTranscript({
const requestInFlightRef = useRef(false);
const liveVoice = useLiveVoice({
onUtterance: enqueueVoiceUtterance,
onHeardTurn: (text) => recordVoiceTurnRef.current('user', text),
onSpokenTurn: (text) => {
if (requestInFlightRef.current) {
heldSpokenTurnsRef.current.push(text);
Expand Down Expand Up @@ -1093,9 +1092,9 @@ export function FastSessionTranscript({
}
}, [messages, streamMessages, liveVoiceActive]);

// The call is transcribed into the Session: what the person said when the
// voice answered directly, what the voice said, and where the call started
// and ended. Delegated requests are recorded by the Fast turn they start.
// The call is transcribed into the Session: Fast turns record what the
// person said, this path records what the voice said, and call events mark
// where the conversation started and ended.
const recordVoiceTurn = useCallback(
(role: 'user' | 'assistant', text: string) => {
// The finished words stay on screen until their persisted row arrives.
Expand Down
117 changes: 87 additions & 30 deletions apps/web/src/hooks/useLiveVoice.client.test.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 16 additions & 30 deletions apps/web/src/hooks/useLiveVoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ import {

const DELEGATION_TRANSCRIPT_SETTLE_MS = 250;
/**
* Speech GPT-Live answers itself never produces a delegation. After this much
* silence with no delegation the utterance is recorded as a heard turn so the
* Session transcript still has it.
* Backstop a GPT-Live delegation that never arrives. After this much silence,
* the utterance is sent through Fast without a delegation id.
*/
const UTTERANCE_SILENCE_FLUSH_MS = 1_500;
/** A delegation this soon after a silence flush belongs to that utterance. */
const STALE_DELEGATION_WINDOW_MS = 3_000;
/** GPT-Live has finished a spoken turn once its transcript stops growing. */
const SPOKEN_TURN_SETTLE_MS = 1_200;
const SESSION_START_TIMEOUT_MS = 15_000;
Expand All @@ -43,12 +40,6 @@ interface UseLiveVoiceOptions {
* speaking a turn. This is the spoken record the Session persists.
*/
onSpokenTurn?: (text: string) => void;
/**
* Called with the raw transcript of what the person said each time GPT-Live
* handles it without delegating (small talk), so the Session still records
* it. Delegated utterances reach the Session through `onUtterance`.
*/
onHeardTurn?: (text: string) => void;
/** Called with GPT-Live's words so far while it is speaking a turn. */
onSpokenTurnDelta?: (text: string) => void;
/** Called with the person's words so far while they are speaking. */
Expand Down Expand Up @@ -119,7 +110,6 @@ async function waitForIceGathering(peer: RTCPeerConnection): Promise<void> {
export function useLiveVoice({
onUtterance,
onSpokenTurn,
onHeardTurn,
onSpokenTurnDelta,
onHeardTurnDelta,
disabled = false,
Expand All @@ -134,8 +124,6 @@ export function useLiveVoice({
const [deliveringUtterances, setDeliveringUtterances] = useState(0);
const onSpokenTurnRef = useRef(onSpokenTurn);
onSpokenTurnRef.current = onSpokenTurn;
const onHeardTurnRef = useRef(onHeardTurn);
onHeardTurnRef.current = onHeardTurn;
const onSpokenTurnDeltaRef = useRef(onSpokenTurnDelta);
onSpokenTurnDeltaRef.current = onSpokenTurnDelta;
const onHeardTurnDeltaRef = useRef(onHeardTurnDelta);
Expand Down Expand Up @@ -164,7 +152,10 @@ export function useLiveVoice({
const pendingDelegationsRef = useRef<string[]>([]);
const delegationTimerRef = useRef<number | null>(null);
const silenceTimerRef = useRef<number | null>(null);
const lastSilenceFlushAtRef = useRef(0);
// Delegations have no utterance identifier. After one is missed, accepting
// any later delegation could attach it to the wrong transcript, so the rest
// of this call uses the ordered silence fallback instead.
const fallbackOnlyRef = useRef(false);
const speakingTimerRef = useRef<number | null>(null);
const deliveryChainRef = useRef<Promise<void>>(Promise.resolve());

Expand Down Expand Up @@ -242,20 +233,22 @@ export function useLiveVoice({
);
}, [flushDelegation]);

// Speech GPT-Live handles itself (small talk) never produces a delegation.
// Once the person has been quiet for a moment, record what they said so the
// Session transcript stays the complete record of the call.
// A missed or delayed GPT-Live delegation must not bypass Fast. Once the
// person has been quiet, submit the utterance without a delegation id. The
// call then stays in fallback-only mode because later delegation events
// cannot be correlated safely with a specific utterance.
const scheduleSilenceFlush = useCallback(() => {
clearSilenceTimer();
silenceTimerRef.current = window.setTimeout(() => {
silenceTimerRef.current = null;
const utterance = stripVoiceAnnotations(inputTranscriptRef.current);
if (pendingDelegationsRef.current.length > 0) return;
inputTranscriptRef.current = '';
lastSilenceFlushAtRef.current = Date.now();
if (utterance) onHeardTurnRef.current?.(utterance);
if (!utterance) return;
fallbackOnlyRef.current = true;
deliverUtterance(utterance, null);
}, UTTERANCE_SILENCE_FLUSH_MS);
}, [clearSilenceTimer]);
}, [clearSilenceTimer, deliverUtterance]);

const handleServerEvent = useCallback(
(raw: string) => {
Expand Down Expand Up @@ -307,15 +300,7 @@ export function useLiveVoice({
break;
case 'session.delegation.created':
if (event.delegation?.target === 'client' && event.delegation.id) {
// A delegation arriving just after the silence flush already sent
// that utterance; attaching it to the next one would skew replies.
if (
!inputTranscriptRef.current.trim() &&
Date.now() - lastSilenceFlushAtRef.current <
STALE_DELEGATION_WINDOW_MS
) {
break;
}
if (fallbackOnlyRef.current) break;
pendingDelegationsRef.current.push(event.delegation.id);
scheduleDelegationFlush();
}
Expand Down Expand Up @@ -385,6 +370,7 @@ export function useLiveVoice({

inputTranscriptRef.current = '';
pendingDelegationsRef.current = [];
fallbackOnlyRef.current = false;
setActive(false);
setStatus('idle');
setStartedAt(null);
Expand Down
Loading
Loading