<key>AiMouseSdk copy.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
- <integer>2</integer>
+ <integer>3</integer>
</dict>
<key>AiMouseSdk.xcscheme_^#shared#^_</key>
<dict>
NS_ASSUME_NONNULL_BEGIN
@interface AiDeviceInfoManager : NSObject
+@property (nonatomic, strong) AiMouseDeviceInfo *deviceInfo;
@property (nonatomic,strong)void (^sendToBleBlock)(NSData *data);
@property (nonatomic,strong)void (^outputLogBlock)(NSString *log);
@property (nonatomic,strong)void (^timeOutBlock)(void);
@interface AiDeviceInfoManager()<AiSenderDelegate>
@property (nonatomic, strong) AiSender *sender;
-@property (nonatomic, strong) AiMouseDeviceInfo *deviceInfo;
+
@property (nonatomic, strong) void (^deviceInfoBlock)(AiMouseDeviceInfo *deviceInfo,NSError *error);
@property (nonatomic, strong) void (^getRSSIBlock)(NSString *value,NSError *error);
@property (nonatomic, strong) void (^getVersionBlock)(NSString *version,NSError *error);
@end
@interface AiMouseDeviceInfo()
+
@property (nonatomic, strong) NSString *productKey;/// 品牌key
@property (nonatomic, strong) NSString *secretKey;/// 品牌Secret
@property (nonatomic, strong) NSString *deviceSecret;///设备Secret
@end
@interface AiMouse()
+@property (nonatomic, assign) BOOL isLoading;///是否正在请求
@property (nonatomic, strong) NSMutableData *voiceData;
@property (nonatomic, strong) SbcConverter *sbcTool;
@property (nonatomic, strong) AiRecordManager *recordManager;
-(instancetype)init{
if (self = [super init]) {
_connectType = AiMouseConnectType_bluetooth;
- self.voiceData = [[NSMutableData alloc] init];
[self.recordManager checkPermissions];
}
return self;
}
+-(NSMutableData *)voiceData{
+ if (_voiceData == nil) {
+ _voiceData = [[NSMutableData alloc] init];
+ }
+ return _voiceData;
+}
+
-(AiDeviceInfoManager *)deviceInfoManager{
if (!_deviceInfoManager) {
}
- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))complete{
+ if (self.isLoading) {
+ complete(self.deviceInfoManager.deviceInfo,nil);
+ return;
+ }
+ self.isLoading = true;
+ dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC);
+ dispatch_after(delayTime, dispatch_get_main_queue(), ^{
+ self.isLoading = false;
+ });
__weak typeof(self) ws = self;
[self.deviceInfoManager getDeviceInfo:^(AiMouseDeviceInfo * _Nonnull deviceInfo, NSError * _Nonnull error) {
if (deviceInfo && ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4)) {
deviceInfo.byteAuthInfo = info;
[ws showLog:deviceInfo.description];
complete(deviceInfo,error);
+ self.isLoading = false;
}];
}
else{
#pragma mark - other
- (void)sendRecordData:(NSData *)data{
// [self showLog:[NSString stringWithFormat:@"[audio] %@",data]];
- if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
+// if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
[self.voiceData appendData:data];
if (self.voiceData.length > 5000) {
if (self.delegate) [self.delegate aiMouseSendRecordData:self.voiceData];
- self.voiceData = [[NSMutableData alloc] init];
+ self.voiceData = nil;
}
- }
- else{
- if (self.delegate) [self.delegate aiMouseSendRecordData:data];
- }
+// }
+// else{
+// if (self.delegate) [self.delegate aiMouseSendRecordData:data];
+// }
}
- (void)sendCmdData:(NSData *)data{
// [self showLog:[NSString stringWithFormat:@"[send] %@",data]];
- (void)startRecord{
// [self showLog:@"开始录音"];
[self.recordManager start];
- self.voiceData = [[NSMutableData alloc] init];
}
- (void)stopRecord:(BOOL)sendCmd{
self.info = [[ByteDanceInfo alloc] init];
stb_app_start_identify();
- [self performSelector:@selector(timeOutAction) withObject:nil afterDelay:5];
+ [self performSelector:@selector(timeOutAction) withObject:nil afterDelay:30];
}
- (void)timeOutAction{
@property (nonatomic,strong)AiMouseDeviceInfo *fullInfo;
@property (nonatomic,assign)NSInteger questTimes;
-@property (nonatomic,strong)NSMutableData *voiceData;
+@property (nonatomic,strong)NSMutableData *deviceData;
+@property (nonatomic, strong) NSMutableData *voiceData;
@end
@implementation M8MouseSdk
_recordManager = [[AiRecordManager alloc] init];
__weak typeof(self) ws = self;
_recordManager.didRecordData = ^(NSData * _Nonnull data) {
- [ws showLog:[NSString stringWithFormat:@"%@",data]];
+ ws.voiceData = [[NSMutableData alloc] init];
[ws sendRecordData:data];
};
}
- (void)switchConnect:(AiMouseConnectType)type isConnected:(BOOL)isConneted{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
if(isConneted ){
- self.voiceData = [[NSMutableData alloc] init];
+ self.deviceData = [[NSMutableData alloc] init];
_connected = true;
_connectType = type;
[self showLog:type == AiMouseConnectType_bluetooth?@"sdk切换到蓝牙模式":@"sdk切换到usb模式"];
}
#pragma mark - ble
- (void)bleReceiveAiData:(NSData *)data{
- [self.voiceData appendData:data];
+ [self.deviceData appendData:data];
[self convertToPcm];
}
- (void)convertToPcm{
- if (self.voiceData.length >= 390) {
- NSData *subData = [self.voiceData subdataWithRange:NSMakeRange(0, 390)];
+ if (self.deviceData.length >= 390) {
+ NSData *subData = [self.deviceData subdataWithRange:NSMakeRange(0, 390)];
NSData *pcm = [self toPcm:subData];
- self.voiceData = [NSMutableData dataWithData:[self.voiceData subdataWithRange:NSMakeRange(390, self.voiceData.length - 390)]];
+ self.deviceData = [NSMutableData dataWithData:[self.deviceData subdataWithRange:NSMakeRange(390, self.deviceData.length - 390)]];
[self sendRecordData:pcm];
[self convertToPcm];
}
}
#pragma mark - other
- (void)sendRecordData:(NSData *)data{
-// [self showLog:[NSString stringWithFormat:@"[send][audio] %@",data]];
- if (self.delegate) [self.delegate m8MouseSendRecordData:data];
+ // if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
+ [self.voiceData appendData:data];
+ if (self.voiceData.length > 5000) {
+ if (self.delegate) [self.delegate m8MouseSendRecordData:self.voiceData];
+ self.voiceData = [[NSMutableData alloc] init];
+ }
+ // }
+ // else{
+ // if (self.delegate) [self.delegate m8MouseSendRecordData:data];
+ // }
}
- (void)sendCmdData:(NSData *)data{
}
#pragma mark - deviceInfo
- (void)startRecord{
+ self.voiceData = [[NSMutableData alloc] init];
[self.recordManager start];
}
- (instancetype)init{
self = [super init];
if (self) {
- self.version = @"MouseSdk_v2025052701";
+ self.version = @"MouseSdk_v2025052901";
}
return self;
}
//@"08":@"08",
/// 其他未定义
- (void)m8MouseSendCmdData:(NSData *)data{
- NSLog(@"%@",data);
uint8 cmd;
[data getBytes:&cmd length:1];
if( cmd == 0x01){
- (void)sendRecordingCallBackToApp:(NSData *)data{
[self.recordData appendData:data];
if (self.recordingCallBack) {
+ [self showLog:@"超过5000B,发送给app"];
// 将NSData转换为Base64编码的字符串
self.recordingCallBack( [data base64EncodedStringWithOptions:0]);
}
- (void)saveLog:(NSString *)log;
-- (NSString *)getLogs;
-
@end
@interface LogManager()
@property (nonatomic, strong) NSFileHandle *fileHandle;
-@property (nonatomic, strong) NSMutableArray *logList;
@end
- (instancetype)init {
if (self = [super init]) {
- self.logList = [[NSMutableArray alloc] init];
}
return self;
}
- (void)saveLog:(NSString *)log {
[self.fileHandle writeData:[log dataUsingEncoding:NSUTF8StringEncoding]];
- [self.logList addObject:log];
}
-
-- (NSString *)getLogs{
- // NSData *data = [[NSData alloc] initWithContentsOfFile:[self getPath]];
- // NSString *log = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- // return log;
- NSString *log = [self.logList componentsJoinedByString:@""];
- return log;
-}
@end
@end
@interface TlwMouse()
-
+@property (nonatomic, strong) NSMutableData *voiceData;
@property (nonatomic, strong) AiRecordManager *recordManager;
@property (nonatomic,strong)void (^dongleStateCallBack)(BOOL success);
return self;
}
+-(NSMutableData *)voiceData{
+ if (_voiceData == nil) {
+ _voiceData = [[NSMutableData alloc] init];
+ }
+ return _voiceData;
+}
+
- (AiRecordManager *)recordManager{
if (!_recordManager) {
_recordManager = [[AiRecordManager alloc] init];
__weak typeof(self) ws = self;
_recordManager.didRecordData = ^(NSData * _Nonnull data) {
- [ws showLog:[NSString stringWithFormat:@"[audio]%@",data]];
[ws sendRecordData:data];
};
}
#pragma mark - other
- (void)sendRecordData:(NSData *)data{
// [self showLog:[NSString stringWithFormat:@"[send][audio] %@",data]];
- if (self.delegate) [self.delegate tlwMouseSendRecordData:data];
+
+// if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
+ [self.voiceData appendData:data];
+ if (self.voiceData.length > 5000) {
+ if (self.delegate) [self.delegate tlwMouseSendRecordData:self.voiceData];
+ self.voiceData = nil;
+ }
+// }
+// else{
+// if (self.delegate) [self.delegate tlwMouseSendRecordData:data];
+// }
}
- (void)sendCmdData:(NSData *)data{
// Do any additional setup after loading the view.
[self setupUI];
[self setupDeviceManger];
- [self getDeviceIinfo];
+
}
- (void)loadView{
if(connected){
ws.typeLabel.stringValue = connectType == 0 ?@"连接模式:蓝牙":@"连接模式:hid";
ws.connectLabel.stringValue = connected?@"连接状态:已连接":@"连接状态:未连接";
- [ws geviceInfoAction];
+// [ws geviceInfoAction];
+ [self getDeviceIinfo];
}
else{
ws.typeLabel.stringValue = @"连接模式:--";
// NSLog(@"开始录音");
};
manager.recordingCallBack = ^(NSString * _Nonnull data) {
- //NSLog(@"%@",[NSString stringWithFormat:@"语音数据 = %@",data]);
+// NSLog(@"%@",[NSString stringWithFormat:@"收到语音数据 = %@",data]);
};
manager.finishRecoredCallBack = ^(NSString * _Nonnull data) {
//NSLog(@"%@",[NSString stringWithFormat:@"结束录音 = %@",data]);
if ([DeviceManger shared].isConneted) {
[self geviceInfoAction];
}
- //[self performSelector:@selector(getDeviceIinfo) withObject:nil afterDelay:10];
+ [self performSelector:@selector(getDeviceIinfo) withObject:nil afterDelay:1];
}
@end
<key>Masonry.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
- <integer>3</integer>
+ <integer>4</integer>
</dict>
<key>Pods-MouseSdk.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
- <integer>4</integer>
+ <integer>2</integer>
</dict>
</dict>
</dict>