89 lines
2.3 KiB
Objective-C
89 lines
2.3 KiB
Objective-C
//
|
||
// ConversationOrchestrator.h
|
||
// keyBoard
|
||
//
|
||
// Created by Mac on 2026/1/15.
|
||
//
|
||
|
||
#import <Foundation/Foundation.h>
|
||
|
||
NS_ASSUME_NONNULL_BEGIN
|
||
|
||
/// 对话状态
|
||
typedef NS_ENUM(NSInteger, ConversationState) {
|
||
ConversationStateIdle = 0, // 空闲
|
||
ConversationStateListening, // 正在录音
|
||
ConversationStateRecognizing, // 正在识别(等待 ASR 结果)
|
||
ConversationStateThinking, // 正在思考(等待 LLM 回复)
|
||
ConversationStateSpeaking // 正在播报 TTS
|
||
};
|
||
|
||
/// 对话编排器
|
||
/// 核心状态机,串联所有模块,处理打断逻辑
|
||
@interface ConversationOrchestrator : NSObject
|
||
|
||
/// 当前状态
|
||
@property(nonatomic, assign, readonly) ConversationState state;
|
||
|
||
/// 当前对话 ID
|
||
@property(nonatomic, copy, readonly, nullable) NSString *conversationId;
|
||
|
||
#pragma mark - Callbacks
|
||
|
||
/// 用户最终识别文本回调
|
||
@property(nonatomic, copy, nullable) void (^onUserFinalText)(NSString *text);
|
||
|
||
/// AI 可见文本回调(打字机效果)
|
||
@property(nonatomic, copy, nullable) void (^onAssistantVisibleText)
|
||
(NSString *text);
|
||
|
||
/// AI 完整回复文本回调
|
||
@property(nonatomic, copy, nullable) void (^onAssistantFullText)(NSString *text)
|
||
;
|
||
|
||
/// 实时识别文本回调(部分结果)
|
||
@property(nonatomic, copy, nullable) void (^onPartialText)(NSString *text);
|
||
|
||
/// 音量更新回调(用于波形 UI)
|
||
@property(nonatomic, copy, nullable) void (^onVolumeUpdate)(float rms);
|
||
|
||
/// 状态变化回调
|
||
@property(nonatomic, copy, nullable) void (^onStateChange)
|
||
(ConversationState state);
|
||
|
||
/// 错误回调
|
||
@property(nonatomic, copy, nullable) void (^onError)(NSError *error);
|
||
|
||
/// AI 开始说话回调
|
||
@property(nonatomic, copy, nullable) void (^onSpeakingStart)(void);
|
||
|
||
/// AI 说话结束回调
|
||
@property(nonatomic, copy, nullable) void (^onSpeakingEnd)(void);
|
||
|
||
#pragma mark - Configuration
|
||
|
||
/// ASR 服务器 URL
|
||
@property(nonatomic, copy) NSString *asrServerURL;
|
||
|
||
/// LLM 服务器 URL
|
||
@property(nonatomic, copy) NSString *llmServerURL;
|
||
|
||
/// TTS 服务器 URL
|
||
@property(nonatomic, copy) NSString *ttsServerURL;
|
||
|
||
#pragma mark - User Actions
|
||
|
||
/// 用户按下录音按钮
|
||
/// 如果当前正在播放,会自动打断
|
||
- (void)userDidPressRecord;
|
||
|
||
/// 用户松开录音按钮
|
||
- (void)userDidReleaseRecord;
|
||
|
||
/// 手动停止(退出页面等)
|
||
- (void)stop;
|
||
|
||
@end
|
||
|
||
NS_ASSUME_NONNULL_END
|