SLAiSetVc.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // SLAiSetVc.m
  3. // SLAiELTS
  4. //
  5. // Created by Gusont on 2023/5/31.
  6. //
  7. #import "SLAiSetVc.h"
  8. #import "SLBaseTableViewCell.h"
  9. #import "SLMySpeedCell.h"
  10. #import "SLModifyNicknameVc.h"
  11. #import "SLNuisdkPlay.h"
  12. #import "SLSexSetVc.h"
  13. @interface SLAiSetVc ()<UITableViewDelegate, UITableViewDataSource,YMCustomSegmentDelegate>
  14. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  15. @property (nonatomic, strong) NSMutableArray<NSArray<SLPageModelDetail *> *> *dataModels;
  16. @property (nonatomic, strong)SLNuisdkPlay *play;
  17. @end
  18. @implementation SLAiSetVc
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view from its nib.
  22. self.title = @"AI设置";
  23. if (@available(iOS 11.0, *)) {
  24. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  25. } else {
  26. self.automaticallyAdjustsScrollViewInsets = NO;
  27. }
  28. self.tableView.estimatedRowHeight = 100;
  29. [self.tableView registerNibCellWithReuseIdentifierClass:SLBaseTableViewCell.class];
  30. [self.tableView registerNibCellWithReuseIdentifierClass:SLMySpeedCell.class];
  31. self.tableView.backgroundColor = [UIColor colorFormString:@"#F2F3F7"];
  32. }
  33. - (void)viewWillAppear:(BOOL)animated {
  34. [super viewWillAppear: animated];
  35. _dataModels = nil;
  36. [self.tableView reloadData];
  37. }
  38. - (void)dealloc {
  39. [_play stopNuisdkPlay];
  40. _play = nil;
  41. }
  42. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  43. UITableViewCell *cell;
  44. SLPageModelDetail *detail = [[self.dataModels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  45. if (indexPath.section == 0) {
  46. SLBaseTableViewCell *baseCell = [tableView dequeueReusableCellWithIdentifier:@"SLBaseTableViewCell"];
  47. [baseCell confignCell:detail];
  48. cell = baseCell;
  49. }else {
  50. SLMySpeedCell *speedCell = [tableView dequeueReusableCellWithIdentifier:@"SLMySpeedCell"];
  51. speedCell.segmentView.delegate = nil;
  52. [speedCell confignCell:detail];
  53. speedCell.segmentView.delegate = self;
  54. cell = speedCell;
  55. }
  56. return cell;
  57. }
  58. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  59. return [self.dataModels objectAtIndex:section].count;
  60. }
  61. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  62. return self.dataModels.count;
  63. }
  64. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  65. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  66. SLPageModelDetail *detail = [[self.dataModels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
  67. if ([detail.title isEqualToString:@"AI昵称"]) {
  68. SLModifyNicknameVc *vc = [SLModifyNicknameVc loadViewControllewWithNib];
  69. vc.isAiNickName = YES;
  70. [self navPushViewController:vc animated:YES];
  71. }
  72. if ([detail.title isEqualToString:@"性别"]) {
  73. SLSexSetVc *vc = [SLSexSetVc loadViewControllewWithNib];
  74. [self navPushViewController:vc animated:YES];
  75. }
  76. }
  77. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  78. if (indexPath.section == 1) {
  79. return 82.f;
  80. }
  81. return 50.f;
  82. }
  83. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  84. return 14.f;
  85. }
  86. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  87. return 0.001f;
  88. }
  89. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  90. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 14)];
  91. view.backgroundColor = [UIColor colorFormString:@"#F2F3F7"];
  92. return view;
  93. }
  94. - (void)customSegmentSelectIndex:(NSInteger)selectIndex title:(NSString *)title {
  95. NSString *speechRate = [[RoleModel roleModelDict] objectForKey:title];
  96. if ([SLGlobalInfo SharedInstance].loginInfo && speechRate) {
  97. RoleModel *model = [RoleModel mj_objectWithKeyValues:[[SLGlobalInfo SharedInstance].roleModel mj_keyValues]];
  98. if ([title containsString:@"音"]) {
  99. model.language = speechRate;
  100. }else {
  101. model.speechRate = speechRate;
  102. }
  103. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  104. [self.play startTTSWith:SLDefaultPlay roleModel:model finshBlock:^{
  105. }];
  106. });
  107. NSString *url = [title containsString:@"音"] ? @"/api/User/UpdateAILanguage" : @"/api/User/UpdateSpeechRate";
  108. NSDictionary *params = [title containsString:@"音"] ? @{@"language" : speechRate} : @{@"speechRate" : speechRate};
  109. [[SLHttpCenter SharedInstance] getWithUrl:url parameter:params success:^(id responseObject) {
  110. [SLGlobalInfo SharedInstance].roleModel = model;
  111. } failure:^(SPRequestError *error) {
  112. }];
  113. }
  114. }
  115. - (NSMutableArray<NSArray<SLPageModelDetail *> *> *)dataModels {
  116. if (!_dataModels) {
  117. RoleModel *user = [SLGlobalInfo SharedInstance].roleModel;
  118. NSArray *arr = @[
  119. @[[SLPageModelDetail initWithTitle:@"AI昵称" subTitle:user.aiName bgImage:@""],
  120. [SLPageModelDetail initWithTitle:@"性别" subTitle:user.aiSex bgImage:@""],],
  121. @[[SLPageModelDetail initWithTitle:@"口音设置" segments:@[@"美音", @"英音"]],
  122. [SLPageModelDetail initWithTitle:@"难度设置" segments:@[@"简单", @"中等", @"困难"]],
  123. [SLPageModelDetail initWithTitle:@"语速设置" segments:@[@"慢", @"中", @"快"]]],];
  124. _dataModels = [NSMutableArray arrayWithArray:arr];
  125. }
  126. return _dataModels;
  127. }
  128. - (SLNuisdkPlay *)play {
  129. if (!_play) {
  130. _play = [[SLNuisdkPlay alloc] init];
  131. }
  132. return _play;
  133. }
  134. @end