()
| 158 | |
| 159 | // Send a session.update event with the user's settings |
| 160 | function sendSessionUpdate() { |
| 161 | if (!dc || dc.readyState !== 'open') return; |
| 162 | |
| 163 | const instructions = document.getElementById('instructionsInput').value.trim(); |
| 164 | const voice = document.getElementById('voiceInput').value.trim(); |
| 165 | const language = document.getElementById('languageInput').value.trim(); |
| 166 | |
| 167 | // Only send if the user configured something |
| 168 | if (!instructions && !voice && !language) return; |
| 169 | |
| 170 | const session = {}; |
| 171 | |
| 172 | if (instructions) { |
| 173 | session.instructions = instructions; |
| 174 | } |
| 175 | |
| 176 | if (voice || language) { |
| 177 | session.audio = {}; |
| 178 | if (voice) { |
| 179 | session.audio.output = { voice: voice }; |
| 180 | } |
| 181 | if (language) { |
| 182 | session.audio.input = { |
| 183 | transcription: { language: language } |
| 184 | }; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | const event = { |
| 189 | type: 'session.update', |
| 190 | session: session, |
| 191 | }; |
| 192 | |
| 193 | console.log('[session.update]', event); |
| 194 | dc.send(JSON.stringify(event)); |
| 195 | } |
| 196 | |
| 197 | function handleServerEvent(event) { |
| 198 | console.log('[event]', event.type, event); |
no test coverage detected