React hook for handling SSE voice streaming responses. Converts audio blob to base64 and sends as JSON to match server expectations. /
/**
* React hook for handling SSE voice streaming responses.
* Converts audio blob to base64 and sends as JSON to match server expectations.
*/
import { useCallback } from "react";
import { useAudioPlayback } from "./useAudioPlayback";
interface StreamCallbacks {
onUserTranscript?: (text: string) => void;
onTranscript?: (text: string, full: string) => void;
onComplete?: (transcript: string) => void;
onError?: (error: Error) => void;
}
export function useVoiceStream(callbacks: StreamCallbacks = {}) {
const playback = useAudioPlayback();
const streamVoiceResponse = useCallback(
async (url: string, audioBlob: Blob) => {
await playback.init();
playback.clear();
// Convert blob to base64 for JSON body (server expects express.json())
const base64Aud
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search 40K more like it.
Get a free API key