|
@@ -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 当前读到的单个字,是一个估算值不一定准确
|