123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //
- // YMSoundShowcaseViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/3/8.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMSoundShowcaseViewModel.h"
- @interface YMSoundShowcaseViewModel ()
- /// 语音提词器列表
- @property (nonatomic, strong, readwrite) NSArray *voiceTeleprompterDataArray;
- /// 语音提词器内容
- @property (nonatomic, strong, readwrite) NSAttributedString *voiceTeleprompterContent;
- @end
- @implementation YMSoundShowcaseViewModel
- - (void)ym_initialize{
- [super ym_initialize];
-
- self.customNavTitle = @"声音展示";
- }
- - (void)refreshVoiceTelepromptertData{
- [LCHttpHelper requestWithURLString:VoiceList parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- NSString *voiceTeleprompterStr = @"";
- NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
- NSArray *result = [data arrayValueForKey:@"list" defaultValue:@[]];
-
- if (!OCArrayIsEmpty(result)) {
- self.voiceTeleprompterDataArray = result;
-
- voiceTeleprompterStr = [self.voiceTeleprompterDataArray objectAtIndex:0];
-
- NSMutableAttributedString *voiceTeleprompterContentAttributed = [[NSMutableAttributedString alloc]initWithString:voiceTeleprompterStr];
- voiceTeleprompterContentAttributed.yy_font = LCFont(14);
- voiceTeleprompterContentAttributed.yy_color = HexColorFromRGB(0x262626);
- voiceTeleprompterContentAttributed.yy_lineSpacing = 5;
- voiceTeleprompterContentAttributed.yy_alignment = NSTextAlignmentJustified;
-
- self.voiceTeleprompterContent = voiceTeleprompterContentAttributed;
-
- }
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
-
- [self randomVoiceTeleprompter];
-
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
-
- [self randomVoiceTeleprompter];
- }];
- }
- - (void)randomVoiceTeleprompter{
- if (!OCArrayIsEmpty(self.voiceTeleprompterDataArray)) {
-
- NSInteger index = arc4random() % self.voiceTeleprompterDataArray.count;
-
- NSString *voiceTeleprompterStr = [self.voiceTeleprompterDataArray objectAtIndex:index];
-
- NSMutableAttributedString *voiceTeleprompterContentAttributed = [[NSMutableAttributedString alloc]initWithString:voiceTeleprompterStr];
- voiceTeleprompterContentAttributed.yy_font = LCFont(14);
- voiceTeleprompterContentAttributed.yy_color = HexColorFromRGB(0x262626);
- voiceTeleprompterContentAttributed.yy_lineSpacing = 5;
- voiceTeleprompterContentAttributed.yy_alignment = NSTextAlignmentJustified;
-
- self.voiceTeleprompterContent = voiceTeleprompterContentAttributed;
-
- }
- }
- - (void)uploadTemplateVoiceURL:(NSURL *)templateVoiceURL TemplateVoiceDuration:(NSInteger)templateVoiceDuration{
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"上传中..."];
- [LCCommonHttp uploadWithAudioPath:templateVoiceURL.resourceSpecifier Type:@"mp3" successBlock:^(NSString *ossFilePath) {
- @strongify(self)
- [ZCHUDHelper dismiss];
- if (!OCStringIsEmpty(ossFilePath)) {
- if (self.templateVoiceBlock) {
- self.templateVoiceBlock(ossFilePath, templateVoiceDuration);
- [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
- }
- }
- }];
- }
- @end
|