This commit is contained in:
2026-01-21 17:25:38 +08:00
parent d1d47336c2
commit 36c0b0b210
10 changed files with 1877 additions and 10 deletions

View File

@@ -0,0 +1,57 @@
//
// VoiceChatWebSocketClient.h
// keyBoard
//
// Created by Mac on 2026/1/21.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@protocol VoiceChatWebSocketClientDelegate <NSObject>
@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<VoiceChatWebSocketClientDelegate> 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