1
This commit is contained in:
@@ -9,11 +9,13 @@
|
||||
#import "KBPersonaChatCell.h"
|
||||
#import "KBPersonaModel.h"
|
||||
#import "KBVoiceInputBar.h"
|
||||
#import "KBVoiceRecordManager.h"
|
||||
#import "KBVoiceToTextManager.h"
|
||||
#import "AiVM.h"
|
||||
#import "KBHUD.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
@interface KBAIHomeVC () <UICollectionViewDelegate, UICollectionViewDataSource, KBVoiceToTextManagerDelegate>
|
||||
@interface KBAIHomeVC () <UICollectionViewDelegate, UICollectionViewDataSource, KBVoiceToTextManagerDelegate, KBVoiceRecordManagerDelegate>
|
||||
|
||||
/// 人设列表容器
|
||||
@property (nonatomic, strong) UICollectionView *collectionView;
|
||||
@@ -24,6 +26,9 @@
|
||||
/// 语音转写管理器
|
||||
@property (nonatomic, strong) KBVoiceToTextManager *voiceToTextManager;
|
||||
|
||||
/// 录音管理器
|
||||
@property (nonatomic, strong) KBVoiceRecordManager *voiceRecordManager;
|
||||
|
||||
/// 人设数据
|
||||
@property (nonatomic, strong) NSMutableArray<KBPersonaModel *> *personas;
|
||||
|
||||
@@ -66,6 +71,7 @@
|
||||
|
||||
[self setupUI];
|
||||
[self setupVoiceToTextManager];
|
||||
[self setupVoiceRecordManager];
|
||||
[self loadPersonas];
|
||||
}
|
||||
|
||||
@@ -245,9 +251,17 @@
|
||||
- (void)setupVoiceToTextManager {
|
||||
self.voiceToTextManager = [[KBVoiceToTextManager alloc] initWithInputBar:self.voiceInputBar];
|
||||
self.voiceToTextManager.delegate = self;
|
||||
self.voiceToTextManager.deepgramEnabled = NO;
|
||||
[self.voiceToTextManager prepareConnection];
|
||||
}
|
||||
|
||||
/// 5:录音管理
|
||||
- (void)setupVoiceRecordManager {
|
||||
self.voiceRecordManager = [[KBVoiceRecordManager alloc] init];
|
||||
self.voiceRecordManager.delegate = self;
|
||||
self.voiceRecordManager.minRecordDuration = 1.0;
|
||||
}
|
||||
|
||||
- (NSInteger)currentCompanionId {
|
||||
if (self.personas.count == 0) {
|
||||
return 0;
|
||||
@@ -381,4 +395,38 @@
|
||||
NSLog(@"[KBAIHomeVC] 语音识别失败:%@", error.localizedDescription);
|
||||
}
|
||||
|
||||
- (void)voiceToTextManagerDidBeginRecording:(KBVoiceToTextManager *)manager {
|
||||
[self.voiceRecordManager startRecording];
|
||||
}
|
||||
|
||||
- (void)voiceToTextManagerDidEndRecording:(KBVoiceToTextManager *)manager {
|
||||
[self.voiceRecordManager stopRecording];
|
||||
}
|
||||
|
||||
- (void)voiceToTextManagerDidCancelRecording:(KBVoiceToTextManager *)manager {
|
||||
[self.voiceRecordManager cancelRecording];
|
||||
}
|
||||
|
||||
#pragma mark - KBVoiceRecordManagerDelegate
|
||||
|
||||
- (void)voiceRecordManager:(KBVoiceRecordManager *)manager
|
||||
didFinishRecordingAtURL:(NSURL *)fileURL
|
||||
duration:(NSTimeInterval)duration {
|
||||
NSDictionary *attributes = [[NSFileManager defaultManager]
|
||||
attributesOfItemAtPath:fileURL.path
|
||||
error:nil];
|
||||
unsigned long long fileSize = [attributes[NSFileSize] unsignedLongLongValue];
|
||||
NSLog(@"[KBAIHomeVC] 录音完成,时长: %.2fs,大小: %llu bytes", duration, fileSize);
|
||||
}
|
||||
|
||||
- (void)voiceRecordManagerDidRecordTooShort:(KBVoiceRecordManager *)manager {
|
||||
NSLog(@"[KBAIHomeVC] 录音过短,已忽略");
|
||||
[KBHUD showError:KBLocalized(@"录音时间过短,请重新录音")];
|
||||
}
|
||||
|
||||
- (void)voiceRecordManager:(KBVoiceRecordManager *)manager
|
||||
didFailWithError:(NSError *)error {
|
||||
NSLog(@"[KBAIHomeVC] 录音失败:%@", error.localizedDescription);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user