feat/ 添加app-expo三种环境切换,待测试 调整tts

This commit is contained in:
Kevin
2026-03-19 09:58:02 +08:00
parent faf7607bf9
commit 15512834d2
12 changed files with 187 additions and 18 deletions

View File

@@ -112,6 +112,7 @@ export function useEndConversation() {
interface UseRealtimeSessionOptions {
conversationId: string;
enabled?: boolean;
onTtsAudio?: (audioBase64: string) => void;
}
const MIN_RECORDING_DURATION_SEC = 1;
@@ -136,6 +137,7 @@ interface RealtimeSessionState {
export function useRealtimeSession({
conversationId,
enabled = true,
onTtsAudio,
}: UseRealtimeSessionOptions): RealtimeSessionState {
const queryClient = useQueryClient();
const sessionRef = useRef<RealtimeSession | null>(null);
@@ -168,6 +170,7 @@ export function useRealtimeSession({
conversationId,
queryClient,
onStreamingText: handleStreamingText,
onTtsAudio,
onError: handleError,
onStateChange: setConnectionState,
});
@@ -181,7 +184,7 @@ export function useRealtimeSession({
setConnectionState('disconnected');
setStreamingMessage(null);
};
}, [conversationId, enabled, queryClient, handleStreamingText, handleError]);
}, [conversationId, enabled, queryClient, handleStreamingText, handleError, onTtsAudio]);
const sendText = useCallback(
(text: string) => {

View File

@@ -18,6 +18,7 @@ interface RealtimeSessionOptions {
conversationId: string;
queryClient: QueryClient;
onStreamingText?: StreamingTextCallback;
onTtsAudio?: (audioBase64: string) => void;
onError?: ErrorCallback;
onStateChange?: WsStateListener;
}
@@ -38,6 +39,7 @@ export class RealtimeSession {
private conversationId: string;
private queryClient: QueryClient;
private onStreamingText?: StreamingTextCallback;
private onTtsAudio?: (audioBase64: string) => void;
private onError?: ErrorCallback;
private unsubEvent: (() => void) | null = null;
private unsubState: (() => void) | null = null;
@@ -49,6 +51,7 @@ export class RealtimeSession {
this.conversationId = options.conversationId;
this.queryClient = options.queryClient;
this.onStreamingText = options.onStreamingText;
this.onTtsAudio = options.onTtsAudio;
this.onError = options.onError;
this.unsubEvent = this.client.onEvent(this.handleEvent);
@@ -117,6 +120,11 @@ export class RealtimeSession {
return;
}
if (event.kind === 'tts_audio_received') {
this.onTtsAudio?.(event.audioBase64);
return;
}
handleWsEvent(this.queryClient, event);
if (event.kind === 'session_error') {