This commit is contained in:
2026-01-26 18:43:07 +08:00
parent 6a177ceebc
commit a22599feda
4 changed files with 241 additions and 27 deletions

View File

@@ -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