123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- //
- // SLAiSetVc.m
- // SLAiELTS
- //
- // Created by Gusont on 2023/5/31.
- //
- #import "SLAiSetVc.h"
- #import "SLBaseTableViewCell.h"
- #import "SLMySpeedCell.h"
- #import "SLModifyNicknameVc.h"
- #import "SLNuisdkPlay.h"
- #import "SLSexSetVc.h"
- @interface SLAiSetVc ()<UITableViewDelegate, UITableViewDataSource,YMCustomSegmentDelegate>
- @property (weak, nonatomic) IBOutlet UITableView *tableView;
- @property (nonatomic, strong) NSMutableArray<NSArray<SLPageModelDetail *> *> *dataModels;
- @property (nonatomic, strong)SLNuisdkPlay *play;
- @end
- @implementation SLAiSetVc
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view from its nib.
- self.title = @"AI设置";
- if (@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- self.tableView.estimatedRowHeight = 100;
- [self.tableView registerNibCellWithReuseIdentifierClass:SLBaseTableViewCell.class];
- [self.tableView registerNibCellWithReuseIdentifierClass:SLMySpeedCell.class];
- self.tableView.backgroundColor = [UIColor colorFormString:@"#F2F3F7"];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear: animated];
- _dataModels = nil;
- [self.tableView reloadData];
- }
- - (void)dealloc {
- [_play stopNuisdkPlay];
- _play = nil;
- }
- - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
- UITableViewCell *cell;
- SLPageModelDetail *detail = [[self.dataModels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
- if (indexPath.section == 0) {
- SLBaseTableViewCell *baseCell = [tableView dequeueReusableCellWithIdentifier:@"SLBaseTableViewCell"];
- [baseCell confignCell:detail];
- cell = baseCell;
- }else {
- SLMySpeedCell *speedCell = [tableView dequeueReusableCellWithIdentifier:@"SLMySpeedCell"];
- speedCell.segmentView.delegate = nil;
- [speedCell confignCell:detail];
- speedCell.segmentView.delegate = self;
- cell = speedCell;
- }
- return cell;
- }
- - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [self.dataModels objectAtIndex:section].count;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return self.dataModels.count;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- SLPageModelDetail *detail = [[self.dataModels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
- if ([detail.title isEqualToString:@"AI昵称"]) {
- SLModifyNicknameVc *vc = [SLModifyNicknameVc loadViewControllewWithNib];
- vc.isAiNickName = YES;
- [self navPushViewController:vc animated:YES];
- }
- if ([detail.title isEqualToString:@"性别"]) {
- SLSexSetVc *vc = [SLSexSetVc loadViewControllewWithNib];
- [self navPushViewController:vc animated:YES];
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 1) {
- return 82.f;
- }
- return 50.f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 14.f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0.001f;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, 14)];
- view.backgroundColor = [UIColor colorFormString:@"#F2F3F7"];
- return view;
- }
- - (void)customSegmentSelectIndex:(NSInteger)selectIndex title:(NSString *)title {
- NSString *speechRate = [[RoleModel roleModelDict] objectForKey:title];
- if ([SLGlobalInfo SharedInstance].loginInfo && speechRate) {
- RoleModel *model = [RoleModel mj_objectWithKeyValues:[[SLGlobalInfo SharedInstance].roleModel mj_keyValues]];
- if ([title containsString:@"音"]) {
- model.language = speechRate;
- }else {
- model.speechRate = speechRate;
- }
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.play startTTSWith:SLDefaultPlay roleModel:model finshBlock:^{
- }];
- });
- NSString *url = [title containsString:@"音"] ? @"/api/User/UpdateAILanguage" : @"/api/User/UpdateSpeechRate";
- NSDictionary *params = [title containsString:@"音"] ? @{@"language" : speechRate} : @{@"speechRate" : speechRate};
- [[SLHttpCenter SharedInstance] getWithUrl:url parameter:params success:^(id responseObject) {
- [SLGlobalInfo SharedInstance].roleModel = model;
- } failure:^(SPRequestError *error) {
- }];
- }
- }
- - (NSMutableArray<NSArray<SLPageModelDetail *> *> *)dataModels {
- if (!_dataModels) {
- RoleModel *user = [SLGlobalInfo SharedInstance].roleModel;
- NSArray *arr = @[
- @[[SLPageModelDetail initWithTitle:@"AI昵称" subTitle:user.aiName bgImage:@""],
- [SLPageModelDetail initWithTitle:@"性别" subTitle:user.aiSex bgImage:@""],],
- @[[SLPageModelDetail initWithTitle:@"口音设置" segments:@[@"美音", @"英音"]],
- [SLPageModelDetail initWithTitle:@"难度设置" segments:@[@"简单", @"中等", @"困难"]],
- [SLPageModelDetail initWithTitle:@"语速设置" segments:@[@"慢", @"中", @"快"]]],];
- _dataModels = [NSMutableArray arrayWithArray:arr];
- }
- return _dataModels;
- }
- - (SLNuisdkPlay *)play {
- if (!_play) {
- _play = [[SLNuisdkPlay alloc] init];
- }
- return _play;
- }
- @end
|