YMSoundShowcaseViewModel.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // YMSoundShowcaseViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/8.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMSoundShowcaseViewModel.h"
  9. @interface YMSoundShowcaseViewModel ()
  10. /// 语音提词器列表
  11. @property (nonatomic, strong, readwrite) NSArray *voiceTeleprompterDataArray;
  12. /// 语音提词器内容
  13. @property (nonatomic, strong, readwrite) NSAttributedString *voiceTeleprompterContent;
  14. @end
  15. @implementation YMSoundShowcaseViewModel
  16. - (void)ym_initialize{
  17. [super ym_initialize];
  18. self.customNavTitle = @"声音展示";
  19. }
  20. - (void)refreshVoiceTelepromptertData{
  21. [LCHttpHelper requestWithURLString:VoiceList parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  22. NSDictionary* dict = (NSDictionary*)responseObject;
  23. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  24. if (code == 0) {
  25. NSString *voiceTeleprompterStr = @"";
  26. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  27. NSArray *result = [data arrayValueForKey:@"list" defaultValue:@[]];
  28. if (!OCArrayIsEmpty(result)) {
  29. self.voiceTeleprompterDataArray = result;
  30. voiceTeleprompterStr = [self.voiceTeleprompterDataArray objectAtIndex:0];
  31. NSMutableAttributedString *voiceTeleprompterContentAttributed = [[NSMutableAttributedString alloc]initWithString:voiceTeleprompterStr];
  32. voiceTeleprompterContentAttributed.yy_font = LCFont(14);
  33. voiceTeleprompterContentAttributed.yy_color = HexColorFromRGB(0x262626);
  34. voiceTeleprompterContentAttributed.yy_lineSpacing = 5;
  35. voiceTeleprompterContentAttributed.yy_alignment = NSTextAlignmentJustified;
  36. self.voiceTeleprompterContent = voiceTeleprompterContentAttributed;
  37. }
  38. }else{
  39. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  40. [self randomVoiceTeleprompter];
  41. }
  42. } failure:^(NSError *error) {
  43. [ZCHUDHelper showTitle:error.localizedDescription];
  44. [self randomVoiceTeleprompter];
  45. }];
  46. }
  47. - (void)randomVoiceTeleprompter{
  48. if (!OCArrayIsEmpty(self.voiceTeleprompterDataArray)) {
  49. NSInteger index = arc4random() % self.voiceTeleprompterDataArray.count;
  50. NSString *voiceTeleprompterStr = [self.voiceTeleprompterDataArray objectAtIndex:index];
  51. NSMutableAttributedString *voiceTeleprompterContentAttributed = [[NSMutableAttributedString alloc]initWithString:voiceTeleprompterStr];
  52. voiceTeleprompterContentAttributed.yy_font = LCFont(14);
  53. voiceTeleprompterContentAttributed.yy_color = HexColorFromRGB(0x262626);
  54. voiceTeleprompterContentAttributed.yy_lineSpacing = 5;
  55. voiceTeleprompterContentAttributed.yy_alignment = NSTextAlignmentJustified;
  56. self.voiceTeleprompterContent = voiceTeleprompterContentAttributed;
  57. }
  58. }
  59. - (void)uploadTemplateVoiceURL:(NSURL *)templateVoiceURL TemplateVoiceDuration:(NSInteger)templateVoiceDuration{
  60. @weakify(self)
  61. [ZCHUDHelper showWithStatus:@"上传中..."];
  62. [LCCommonHttp uploadWithAudioPath:templateVoiceURL.resourceSpecifier Type:@"mp3" successBlock:^(NSString *ossFilePath) {
  63. @strongify(self)
  64. [ZCHUDHelper dismiss];
  65. if (!OCStringIsEmpty(ossFilePath)) {
  66. if (self.templateVoiceBlock) {
  67. self.templateVoiceBlock(ossFilePath, templateVoiceDuration);
  68. [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
  69. }
  70. }
  71. }];
  72. }
  73. @end