- Notifications
You must be signed in to change notification settings - Fork8
svelte component for using the openai realtime api
License
flo-bit/svelte-openai-realtime-api
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
this is a svelte component for using the openai realtime api (and mostly a direct port to svelte of theopenai-realtime-console repository).
it allows you to easily use the openai realtime api in your svelte(kit) project.
work in progress, but it should be functional.
demos here (enter your own api key, as always be careful with stuff like that and e.g. use a 2$ limited api key):
basic chat:https://flo-bit.dev/svelte-openai-realtime-api/
chat with visualizations:https://flo-bit.dev/svelte-openai-realtime-api/visualizations-chat
realtime-visualization2.mp4
Warning
this is the setup for the client side only version of the realtime api, you will need to use a relay server to use this in production.see further down for more information on how to use a relay server.
copy the
src/lib/realtime/
folder from this repository into your sveltekit projectssrc/lib/
folderinstall the dependency:
$ npm i openai/openai-realtime-api-beta
- import the
Realtime
component into your svelte file and use it e.g. like so:
<scriptlang="ts">importRealtimefrom'$lib/realtime/Realtime.svelte';importtype {ItemType }from'@openai/realtime-api-beta/dist/lib/client';let startConversation: ()=>Promise<void>;let endConversation: ()=>Promise<void>;let turnDetection:'server_vad'|'none'='server_vad';let items:ItemType[]= [];let isConnected=false;let isRecording=false;let startRecording: ()=>Promise<void>;let stopRecording: ()=>Promise<void>;// set your api key herelet apiKey='';</script>{#ifapiKey}<Realtimebind:startConversationbind:endConversationbind:isConnectedbind:isRecordingbind:startRecordingbind:stopRecordingbind:items{turnDetection}{apiKey}/>{/if}
seesrc/routes/+page.svelte
for a full example.
seesrc/routes/visulizations-chat/+page.svelte
for an example of how to visualize the audio input and output. andsrc/routes/visulizations-input/+page.svelte
for all currently available visualizations.
demo here:https://flo-bit.dev/svelte-openai-realtime-api/visualizations-input
for production use, you will need to use a relay server to use the realtime api.
add
OPENAI_API_KEY
to your.env
filetell the Realtime component to use the relay server:
<RealtimeuseRelayServer />
then you have two options:
Warning
this currently only works in development mode, if you want to use this in production you will need to run the relay server independently.if you have any ideas on how to make this work in production, please let me know.
change yourvite.config.ts
to this:
import{realtimeWebSocketServer}from'./src/lib/realtime/realtime_server';import{sveltekit}from'@sveltejs/kit/vite';import{defineConfig}from'vite';exportdefaultdefineConfig({plugins:[sveltekit(),realtimeWebSocketServer]});
copy the
relay-server/
folder (identical to the code in theopenai-realtime-console repository)from this repository into your projectinstall the dependencies:
npm i dotenv openai/openai-realtime-api-beta
- run the relay server:
$ node relay-server/index.js
- add the relay server url to your Realtime component:
<Realtime useRelayServer relayServer="http://localhost:8081" />
- show waveforms
- add tests
- update main demo ui
- add more documentation
- simple setup client side, server side
- all props
- tool calling
- events
- onConnect
- onDisconnect
- onError
- onInterrupt
- onRealtimeEvent
- onConversationUpdate
- speechStart
- speechStop
- error handling
- pause/resume recording
- send text message
- update props
- instructions
- voice
- vad settings
MIT
About
svelte component for using the openai realtime api
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.