MCPcopy Index your code
hub / github.com/TanStack/ai / useRealtime

Function useRealtime

examples/ts-react-chat/src/lib/use-realtime.ts:56–104  ·  view source on GitHub ↗
({
  provider,
  language,
  voice,
  outputModalities,
  temperature,
  maxOutputTokens,
  semanticEagerness,
}: {
  provider: Provider
  language?: string
  voice?: string
  outputModalities?: Array<'audio' | 'text'>
  temperature?: number
  maxOutputTokens?: number | 'inf'
  semanticEagerness?: 'low' | 'medium' | 'high'
})

Source from the content-addressed store, hash-verified

54}
55
56export function useRealtime({
57 provider,
58 language,
59 voice,
60 outputModalities,
61 temperature,
62 maxOutputTokens,
63 semanticEagerness,
64}: {
65 provider: Provider
66 language?: string
67 voice?: string
68 outputModalities?: Array<'audio' | 'text'>
69 temperature?: number
70 maxOutputTokens?: number | 'inf'
71 semanticEagerness?: 'low' | 'medium' | 'high'
72}) {
73 return useRealtimeChat({
74 getToken: () =>
75 getRealtimeTokenFn({
76 data: {
77 provider,
78 ...(provider === 'elevenlabs' && language ? { language } : {}),
79 },
80 }),
81 adapter: adapterForProvider(provider),
82 instructions: `You are a helpful, friendly voice assistant with access to several tools.
83
84You can:
85- Tell the user the current time and date (getCurrentTime)
86- Get weather information for any location (getWeather)
87- Set reminders for the user (setReminder)
88- Search a knowledge base for information (searchKnowledge)
89
90Keep your responses concise and conversational since this is a voice interface.
91When using tools, briefly explain what you're doing and then share the results naturally.
92If the user sends an image, describe what you see and answer any questions about it.
93Be friendly and engaging!`,
94 voice: voice ?? (provider === 'grok' ? 'eve' : 'alloy'),
95 tools: realtimeClientTools,
96 outputModalities,
97 temperature,
98 maxOutputTokens,
99 semanticEagerness,
100 onError: (err) => {
101 console.error('Realtime error:', err)
102 },
103 })
104}

Callers 1

RealtimePageFunction · 0.90

Calls 3

useRealtimeChatFunction · 0.90
adapterForProviderFunction · 0.85
errorMethod · 0.65

Tested by

no test coverage detected