// // VoiceChatWebSocketClient.h // keyBoard // // Created by Mac on 2026/1/21. // #import NS_ASSUME_NONNULL_BEGIN @protocol VoiceChatWebSocketClientDelegate @optional - (void)voiceChatClientDidConnect; - (void)voiceChatClientDidDisconnect:(NSError *_Nullable)error; - (void)voiceChatClientDidStartSession:(NSString *)sessionId; - (void)voiceChatClientDidStartTurn:(NSInteger)turnIndex; - (void)voiceChatClientDidReceiveEagerEndOfTurnWithTranscript:(NSString *)text confidence:(double)confidence; - (void)voiceChatClientDidResumeTurn; - (void)voiceChatClientDidReceiveInterimTranscript:(NSString *)text; - (void)voiceChatClientDidReceiveFinalTranscript:(NSString *)text; - (void)voiceChatClientDidReceiveLLMStart; - (void)voiceChatClientDidReceiveLLMToken:(NSString *)token; - (void)voiceChatClientDidReceiveAudioChunk:(NSData *)audioData; - (void)voiceChatClientDidCompleteWithTranscript:(NSString *)transcript aiResponse:(NSString *)aiResponse; - (void)voiceChatClientDidReceiveErrorCode:(NSString *)code message:(NSString *)message; - (void)voiceChatClientDidFail:(NSError *)error; @end /// WebSocket client for realtime voice chat. @interface VoiceChatWebSocketClient : NSObject @property(nonatomic, weak) id delegate; /// Base WebSocket URL, e.g. wss://api.yourdomain.com/api/ws/chat @property(nonatomic, copy) NSString *serverURL; @property(nonatomic, assign, readonly, getter=isConnected) BOOL connected; @property(nonatomic, copy, readonly, nullable) NSString *sessionId; - (void)connectWithToken:(NSString *)token; - (void)disconnect; - (void)startSessionWithLanguage:(nullable NSString *)language voiceId:(nullable NSString *)voiceId; - (void)enableAudioSending; - (void)disableAudioSending; - (void)sendAudioPCMFrame:(NSData *)pcmFrame; - (void)endAudio; - (void)cancel; @end NS_ASSUME_NONNULL_END