1
This commit is contained in:
@@ -9,10 +9,11 @@
|
||||
#import "KBPersonaChatCell.h"
|
||||
#import "KBPersonaModel.h"
|
||||
#import "KBVoiceInputBar.h"
|
||||
#import "KBVoiceToTextManager.h"
|
||||
#import "AiVM.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
@interface KBAIHomeVC () <UICollectionViewDelegate, UICollectionViewDataSource, KBVoiceInputBarDelegate>
|
||||
@interface KBAIHomeVC () <UICollectionViewDelegate, UICollectionViewDataSource, KBVoiceToTextManagerDelegate>
|
||||
|
||||
/// 人设列表容器
|
||||
@property (nonatomic, strong) UICollectionView *collectionView;
|
||||
@@ -20,6 +21,9 @@
|
||||
/// 底部语音输入栏
|
||||
@property (nonatomic, strong) KBVoiceInputBar *voiceInputBar;
|
||||
|
||||
/// 语音转写管理器
|
||||
@property (nonatomic, strong) KBVoiceToTextManager *voiceToTextManager;
|
||||
|
||||
/// 人设数据
|
||||
@property (nonatomic, strong) NSMutableArray<KBPersonaModel *> *personas;
|
||||
|
||||
@@ -61,6 +65,7 @@
|
||||
self.aiVM = [[AiVM alloc] init];
|
||||
|
||||
[self setupUI];
|
||||
[self setupVoiceToTextManager];
|
||||
[self loadPersonas];
|
||||
}
|
||||
|
||||
@@ -235,6 +240,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - 4:语音转写
|
||||
|
||||
- (void)setupVoiceToTextManager {
|
||||
self.voiceToTextManager = [[KBVoiceToTextManager alloc] initWithInputBar:self.voiceInputBar];
|
||||
self.voiceToTextManager.delegate = self;
|
||||
[self.voiceToTextManager prepareConnection];
|
||||
}
|
||||
|
||||
#pragma mark - Lazy Load
|
||||
|
||||
- (UICollectionView *)collectionView {
|
||||
@@ -263,41 +276,26 @@
|
||||
- (KBVoiceInputBar *)voiceInputBar {
|
||||
if (!_voiceInputBar) {
|
||||
_voiceInputBar = [[KBVoiceInputBar alloc] init];
|
||||
_voiceInputBar.delegate = self;
|
||||
_voiceInputBar.statusText = @"按住按钮开始对话";
|
||||
}
|
||||
return _voiceInputBar;
|
||||
}
|
||||
|
||||
#pragma mark - KBVoiceInputBarDelegate
|
||||
#pragma mark - KBVoiceToTextManagerDelegate
|
||||
|
||||
- (void)voiceInputBarDidBeginRecording:(KBVoiceInputBar *)inputBar {
|
||||
NSLog(@"[KBAIHomeVC] 开始录音");
|
||||
inputBar.statusText = @"正在聆听...";
|
||||
- (void)voiceToTextManager:(KBVoiceToTextManager *)manager
|
||||
didReceiveFinalText:(NSString *)text {
|
||||
if (text.length == 0) {
|
||||
return;
|
||||
}
|
||||
NSLog(@"[KBAIHomeVC] 语音识别结果:%@", text);
|
||||
|
||||
// TODO: 开始录音逻辑
|
||||
// 1. 检查登录状态
|
||||
// 2. 连接语音识别服务
|
||||
// 3. 开始录音
|
||||
// TODO: 使用识别文本(例如发起聊天请求)
|
||||
}
|
||||
|
||||
- (void)voiceInputBarDidEndRecording:(KBVoiceInputBar *)inputBar {
|
||||
NSLog(@"[KBAIHomeVC] 结束录音");
|
||||
inputBar.statusText = @"正在识别...";
|
||||
|
||||
// TODO: 结束录音逻辑
|
||||
// 1. 停止录音
|
||||
// 2. 发送音频数据
|
||||
// 3. 等待识别结果
|
||||
}
|
||||
|
||||
- (void)voiceInputBarDidCancelRecording:(KBVoiceInputBar *)inputBar {
|
||||
NSLog(@"[KBAIHomeVC] 取消录音");
|
||||
inputBar.statusText = @"已取消";
|
||||
|
||||
// TODO: 取消录音逻辑
|
||||
// 1. 停止录音
|
||||
// 2. 清理资源
|
||||
- (void)voiceToTextManager:(KBVoiceToTextManager *)manager
|
||||
didFailWithError:(NSError *)error {
|
||||
NSLog(@"[KBAIHomeVC] 语音识别失败:%@", error.localizedDescription);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user