Browse Source

读题功能基本完成 up100%

openlockPPP 1 year ago
parent
commit
dff7ea346e

BIN
jiaPei.xcworkspace/xcuserdata/mimasigeling.xcuserdatad/UserInterfaceState.xcuserstate


+ 9 - 0
jiaPei/Modules/OtherModules/ExerciseModule/Controller/RQExerciseSubViewController.m

@@ -255,6 +255,7 @@
 }
 
 - (id<JXPagerSmoothViewListViewDelegate>)pagerView:(JXPagerSmoothView *)pagerView initListAtIndex:(NSInteger)index {
+    NSLog(@"JXCategoryViewDelegate=====initListAtIndex=%zd",index);
     @weakify(self)
     RQTestQuestionsViewController *currentQuestionsViewController = [self.listVcDic objectForKey:[NSString qmui_stringWithNSInteger:index]];
     if (RQObjectIsNil(currentQuestionsViewController)) {
@@ -413,6 +414,14 @@
     self.currentListView = list.tableView;
     self.number = index;
     [self saveNumWithIndex:index];
+    NSLog(@"JXCategoryViewDelegate=====didSelectedItemAtIndex=%zd",index);
+    //控制-语音停止-切换
+    RQExerciseModel *exerciseModel = self.viewModel.questionArr[index];
+    if(![exerciseModel.ydtQuestionModel.Question isEqual:NY_VOICE_MANAGER.paytext]&&
+       //NY_VOICE_MANAGER.state==NYVoiceType_Start&&
+       NY_VOICE_MANAGER.paytext!=nil){
+        [NY_VOICE_MANAGER stopPayVoiceAction];
+    }
 }
 
 - (void)saveNumWithIndex:(NSInteger)index {

+ 29 - 7
jiaPei/Modules/OtherModules/ExerciseModule/ViewModel/ExercisePage/itemViewModel/RQExerciseQuestionItemViewModel.m

@@ -20,7 +20,7 @@
 @property (nonatomic, readwrite, strong) NSString *videoString;
 @property (nonatomic, readwrite, strong) NSMutableAttributedString *spaceAttachment;
 
-//@property (nonatomic, readwrite, strong) QMUIButton *readBtn;
+@property (nonatomic, readwrite, strong) QMUIButton *readBtn;
 
 @end
 
@@ -247,7 +247,7 @@
                                                             attachmentSize:ebtnSize
                                                                alignToFont:[UIFont systemFontOfSize:RQ_Exercise_Module.exerciseFontSize]
                                                                  alignment:YYTextVerticalAlignmentCenter];
-//    self.readBtn = readBtn;
+    self.readBtn = readBtn;
     [testText appendAttributedString:self.spaceAttachment];
     [testText appendAttributedString:readAttachment];
     
@@ -307,12 +307,34 @@
 - (void)buttonActionPayVoicedo:(UIButton *)btn
 {
     btn.selected = !btn.isSelected;
-    QCloudTTSEngine *tts = [QCloudTTSEngine getShareInstance];
-     //如果使用STS临时证书鉴权时需要设置Token
-    [tts setOnlineAuthParam:QDApp_Id SecretId:QDSecret_ID SecretKey:QDSecret_Key Token:nil];
     if(btn.selected){//播放
-        NSString *Question = self.exerciseModel.ydtQuestionModel.Question;
-        [NY_VOICE_MANAGER startPayVoiceActionText:Question];
+        if (NY_VOICE_MANAGER.state == NYVoiceType_Pause){
+            [NY_VOICE_MANAGER resumePayVoiceAction];//恢复
+        }else {
+            NSString *Question = self.exerciseModel.ydtQuestionModel.Question;
+            @weakify(self)
+            [NY_VOICE_MANAGER startPayVoiceActionText:Question completedBlock:^(NYVoiceType voiceType) {
+                switch (voiceType) {
+                    case NYVoiceType_Start:{
+                        self.readBtn.selected = YES;
+                    }break;
+                    case NYVoiceType_Wait:{//完成-等待
+                        self.readBtn.selected = NO;
+                    }break;
+                    case NYVoiceType_Resume:{//恢复
+                        self.readBtn.selected = YES;
+                    }break;
+                    case NYVoiceType_Pause:{//暂停
+                        self.readBtn.selected = NO;
+                    }break;
+                    case NYVoiceType_Stop:{//停止
+                        self.readBtn.selected = NO;
+                    }break;
+                    default:
+                        break;
+                }
+            }];
+        }
     }else {//暂停
         [NY_VOICE_MANAGER pausePayVoiceAction];
     }

+ 25 - 1
jiaPei/OLD/Util/SingletonManger/VoiceManager/NYVoiceManager.h

@@ -10,19 +10,43 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
+
+typedef NS_ENUM(NSUInteger, NYVoiceType) {
+    NYVoiceType_Start = 0,              /// 开始
+    NYVoiceType_Wait = 1,                /// 队列所有音频播放完成,音频等待中
+    NYVoiceType_Resume = 2,                /// 恢复播放
+    NYVoiceType_Pause = 3,                /// 暂停播放
+    NYVoiceType_Stop  = 4,                /// 播放中止
+};
+
 #define NY_VOICE_MANAGER [NYVoiceManager sharedManager]
+/**
+ 播放回调
+ 
+ @param success 是否成功
+ */
+typedef void(^NYVoicePayCompletedBlock)(NYVoiceType voiceType);
 
 @interface NYVoiceManager : NSObject
 
+//当前播放的string
+@property(nonatomic,copy,readonly) NSString *paytext;
+//当前状态
+@property (nonatomic,assign) NYVoiceType state;
+//回调
+@property (nonatomic,copy) NYVoicePayCompletedBlock payCompletedBlock;
+
 + (NYVoiceManager *)sharedManager;
 - (void)ny_configureTTSVoiceDK;
 
 //开播合成播放
-- (void)startPayVoiceActionText:(NSString *)text;
+- (void)startPayVoiceActionText:(NSString *)text completedBlock:(NYVoicePayCompletedBlock)block;
 //暂停合成播放
 - (void)pausePayVoiceAction;
 //停止合成播放
 - (void)stopPayVoiceAction;
+//恢复合成播放
+- (void)resumePayVoiceAction;
 
 @end
 

+ 41 - 19
jiaPei/OLD/Util/SingletonManger/VoiceManager/NYVoiceManager.m

@@ -21,7 +21,6 @@ static dispatch_once_t onceToken;
 // demo 层播放器,如SDK播放器不能满足需求 可以自定义播放器 如下只是一个例子
 //@property(strong) MediaPlayerDemo *player;
 
-
 @property (nonatomic,assign)float onlineSpeed;
 @property (nonatomic,assign)int onlineVoiceType;
 @property (nonatomic,assign)int onlineLanguage;
@@ -102,7 +101,9 @@ static dispatch_once_t onceToken;
 }
 
 //开播合成播放
-- (void)startPayVoiceActionText:(NSString *)text{
+- (void)startPayVoiceActionText:(NSString *)text completedBlock:(nonnull NYVoicePayCompletedBlock)block {
+    _paytext = text;
+    self.payCompletedBlock = block;
     QCloudTTSEngine *tts = [QCloudTTSEngine getShareInstance];
     [self setOnlineParam:tts];
     //设置ProjectId 不设置默认使用0,说明:项目功能用于按项目管理云资源,可以对云资源进行分项目管理,详情见 https://console.cloud.tencent.com/project
@@ -120,6 +121,10 @@ static dispatch_once_t onceToken;
 
 //暂停合成播放
 - (void)pausePayVoiceAction {
+    [self pauseTTSBtnAction:nil];
+}
+//恢复合成播放
+- (void)resumePayVoiceAction {
     [self resumeTTSBtnAction:nil];
 }
 
@@ -129,11 +134,11 @@ static dispatch_once_t onceToken;
 }
 
 - (IBAction)stopTTSBtnAction:(id)sender {
-    
-    [_player StopPlay];
-    [_textArr removeAllObjects];
     QCloudTTSEngine *tts = [QCloudTTSEngine getShareInstance];
     [tts cancel];
+    [_player StopPlay];
+    [_textArr removeAllObjects];
+
 }
 - (IBAction)pauseTTSBtnAction:(id)sender {
     
@@ -264,6 +269,10 @@ static dispatch_once_t onceToken;
 //    _messageTextView.text = [NSString stringWithFormat:@"%@\n onTTSPlayStart",_messageTextView.text];
 //    [self scrollToBottom];
     NSLog(@"onTTSPlayStart");
+    self.state = NYVoiceType_Start;
+    if(self.payCompletedBlock){
+        self.payCompletedBlock(NYVoiceType_Start);
+    }
 }
 
 //队列所有音频播放完成,音频等待中
@@ -271,7 +280,11 @@ static dispatch_once_t onceToken;
     
 //    _messageTextView.text = [NSString stringWithFormat:@"%@\n onTTSPlayWait",_messageTextView.text];
 //    [self scrollToBottom];
+    self.state = NYVoiceType_Wait;
     NSLog(@"onTTSPlayWait");
+    if(self.payCompletedBlock){
+        self.payCompletedBlock(NYVoiceType_Wait);
+    }
 }
 
 //恢复播放
@@ -280,6 +293,10 @@ static dispatch_once_t onceToken;
 //    _messageTextView.text = [NSString stringWithFormat:@"%@\n onTTSPlayResume",_messageTextView.text];
 //    [self scrollToBottom];
     NSLog(@"onTTSPlayResume");
+    self.state = NYVoiceType_Resume;
+    if(self.payCompletedBlock){
+        self.payCompletedBlock(NYVoiceType_Resume);
+    }
 }
 
 //暂停播放
@@ -288,6 +305,10 @@ static dispatch_once_t onceToken;
 //    _messageTextView.text = [NSString stringWithFormat:@"%@\n onTTSPlayPause",_messageTextView.text];
 //    [self scrollToBottom];
     NSLog(@"onTTSPlayPause");
+    self.state = NYVoiceType_Pause;
+    if(self.payCompletedBlock){
+        self.payCompletedBlock(NYVoiceType_Pause);
+    }
 }
 //播放中止
 -(void)onTTSPlayStop{
@@ -296,7 +317,10 @@ static dispatch_once_t onceToken;
 //    _messageTextView.text = [NSString stringWithFormat:@"%@\n onTTSPlayStop",_messageTextView.text];
 //    [self scrollToBottom];
     NSLog(@"onTTSPlayStop");
-    
+    self.state = NYVoiceType_Stop;
+    if(self.payCompletedBlock){
+        self.payCompletedBlock(NYVoiceType_Stop);
+    }
 }
 
 
@@ -314,19 +338,17 @@ static dispatch_once_t onceToken;
 /// @param utteranceId 当前播放音频对应的ID
 -(void) onTTSPlayNextWithText:(NSString* _Nullable)text UtteranceId:(NSString* _Nullable)utteranceId{
     
-//    _messageTextView.text = [NSString stringWithFormat:@"%@\n text==%@\n utteranceId==%@",_messageTextView.text,text,utteranceId];
-//    NSLog(@"text==%@,utteranceId==%@",text,utteranceId);
-//    [self scrollToBottom];
-//    QCloudTTSEngine *tts = [QCloudTTSEngine getShareInstance];
-//    if ([_player getAudioQueueSize] < 10) {
-//
-//        if (_textArr.count > 0) {
-//
-//            NSLog(@"AudioQueueSize=%@",@([_player getAudioQueueSize]));
-//            [tts synthesize:_textArr[0] UtteranceId:[NSString stringWithFormat:@"%d",_cout++]];
-//            [_textArr removeObjectAtIndex:0];
-//        }
-//    }
+    NSLog(@"text==%@,utteranceId==%@",text,utteranceId);
+    QCloudTTSEngine *tts = [QCloudTTSEngine getShareInstance];
+    if ([_player getAudioQueueSize] < 10) {
+
+        if (_textArr.count > 0) {
+
+            NSLog(@"AudioQueueSize=%@",@([_player getAudioQueueSize]));
+            [tts synthesize:_textArr[0] UtteranceId:[NSString stringWithFormat:@"%d",_cout++]];
+            [_textArr removeObjectAtIndex:0];
+        }
+    }
 }
 /// 当前播放的字符,当前播放的字符在所在的句子中的下标.
 /// @param currentWord 当前读到的单个字,是一个估算值不一定准确