| 212 | }; |
| 213 | |
| 214 | const handleStop = async () => { |
| 215 | for (const track of stream.getTracks()) { |
| 216 | track.stop(); |
| 217 | } |
| 218 | streamRef.current = null; |
| 219 | |
| 220 | const audioBlob = new Blob(audioChunksRef.current, { |
| 221 | type: "audio/webm", |
| 222 | }); |
| 223 | |
| 224 | if (audioBlob.size > 0 && onAudioRecordedRef.current) { |
| 225 | setIsProcessing(true); |
| 226 | try { |
| 227 | const transcript = await onAudioRecordedRef.current(audioBlob); |
| 228 | if (transcript) { |
| 229 | onTranscriptionChangeRef.current?.(transcript); |
| 230 | } |
| 231 | } catch { |
| 232 | // Error handling delegated to the onAudioRecorded caller |
| 233 | } finally { |
| 234 | setIsProcessing(false); |
| 235 | } |
| 236 | } |
| 237 | }; |
| 238 | |
| 239 | const handleError = () => { |
| 240 | setIsListening(false); |