From 63729d6d4e5bc2094ee2cb1d0b126549632ee687 Mon Sep 17 00:00:00 2001 From: tisfeng Date: Tue, 16 Jan 2024 22:46:52 +0800 Subject: [PATCH] refactor: rewrite BingLanguageVoice with Swift by Jerry23011 --- Easydict.xcodeproj/project.pbxproj | 10 +++---- .../Service/Bing/BingLanguageVoice.swift | 26 +++++++++++++++++++ .../Service/Bing/EZBingLanguageVoice.h | 24 ----------------- .../Service/Bing/EZBingLanguageVoice.m | 20 -------------- Easydict/Feature/Service/Bing/EZBingRequest.m | 2 +- 5 files changed, 31 insertions(+), 51 deletions(-) create mode 100644 Easydict/Feature/Service/Bing/BingLanguageVoice.swift delete mode 100644 Easydict/Feature/Service/Bing/EZBingLanguageVoice.h delete mode 100644 Easydict/Feature/Service/Bing/EZBingLanguageVoice.m diff --git a/Easydict.xcodeproj/project.pbxproj b/Easydict.xcodeproj/project.pbxproj index a1e5d3696..adc5e75bc 100644 --- a/Easydict.xcodeproj/project.pbxproj +++ b/Easydict.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ 0309E1ED292B439A00AFB76A /* EZTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0309E1EC292B439A00AFB76A /* EZTextView.m */; }; 0309E1F0292B4A5E00AFB76A /* NSView+EZGetViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0309E1EF292B4A5E00AFB76A /* NSView+EZGetViewController.m */; }; 0309E1F4292BD6A100AFB76A /* EZQueryModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 0309E1F3292BD6A100AFB76A /* EZQueryModel.m */; }; + 030DB2612B56CC6500E27DEA /* BingLanguageVoice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 030DB2602B56CC6500E27DEA /* BingLanguageVoice.swift */; }; 0310C8272A94F5DF00B1D81E /* apple-dictionary.html in Resources */ = {isa = PBXBuildFile; fileRef = 0310C8262A94EFA100B1D81E /* apple-dictionary.html */; }; 0313F8702AD5577400A5CFB0 /* EasydictTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0313F86F2AD5577400A5CFB0 /* EasydictTests.m */; }; 031DBD792AE01E130071CF85 /* easydict in Resources */ = {isa = PBXBuildFile; fileRef = 031DBD782AE01E130071CF85 /* easydict */; }; @@ -66,7 +67,6 @@ 037852B329583F5200D0E2CF /* EZServiceCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 037852B229583F5200D0E2CF /* EZServiceCell.m */; }; 037852B629588EDE00D0E2CF /* EZCustomTableRowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 037852B529588EDE00D0E2CF /* EZCustomTableRowView.m */; }; 037852B9295D49F900D0E2CF /* EZTableRowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 037852B8295D49F900D0E2CF /* EZTableRowView.m */; }; - 037BEFCD2A98FDF700D0F17F /* EZBingLanguageVoice.m in Sources */ = {isa = PBXBuildFile; fileRef = 037BEFCC2A98FDF700D0F17F /* EZBingLanguageVoice.m */; }; 037E006D2B3DC098006491C6 /* EZOpenAIService+EZPromptMessages.m in Sources */ = {isa = PBXBuildFile; fileRef = 03CF27FA2B3A787900E19B57 /* EZOpenAIService+EZPromptMessages.m */; }; 038030952B4106800009230C /* CocoaLumberjack in Frameworks */ = {isa = PBXBuildFile; productRef = 038030942B4106800009230C /* CocoaLumberjack */; }; 038030972B4106800009230C /* CocoaLumberjackSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 038030962B4106800009230C /* CocoaLumberjackSwift */; }; @@ -325,6 +325,7 @@ 0309E1EF292B4A5E00AFB76A /* NSView+EZGetViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSView+EZGetViewController.m"; sourceTree = ""; }; 0309E1F2292BD6A100AFB76A /* EZQueryModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZQueryModel.h; sourceTree = ""; }; 0309E1F3292BD6A100AFB76A /* EZQueryModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZQueryModel.m; sourceTree = ""; }; + 030DB2602B56CC6500E27DEA /* BingLanguageVoice.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BingLanguageVoice.swift; sourceTree = ""; }; 0310C8262A94EFA100B1D81E /* apple-dictionary.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "apple-dictionary.html"; sourceTree = ""; }; 0313F86D2AD5577400A5CFB0 /* EasydictTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = EasydictTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 0313F86F2AD5577400A5CFB0 /* EasydictTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EasydictTests.m; sourceTree = ""; }; @@ -414,8 +415,6 @@ 037852B529588EDE00D0E2CF /* EZCustomTableRowView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZCustomTableRowView.m; sourceTree = ""; }; 037852B7295D49F900D0E2CF /* EZTableRowView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZTableRowView.h; sourceTree = ""; }; 037852B8295D49F900D0E2CF /* EZTableRowView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZTableRowView.m; sourceTree = ""; }; - 037BEFCB2A98FDF700D0F17F /* EZBingLanguageVoice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZBingLanguageVoice.h; sourceTree = ""; }; - 037BEFCC2A98FDF700D0F17F /* EZBingLanguageVoice.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZBingLanguageVoice.m; sourceTree = ""; }; 03839141292FBE120009828C /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = ""; }; 03839142292FBE120009828C /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 03839143292FBE120009828C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -2091,8 +2090,7 @@ 6295DE302A84D82E006145F4 /* EZBingTranslateModel.m */, 6295DE322A84EF76006145F4 /* EZBingLookupModel.h */, 6295DE332A84EF76006145F4 /* EZBingLookupModel.m */, - 037BEFCB2A98FDF700D0F17F /* EZBingLanguageVoice.h */, - 037BEFCC2A98FDF700D0F17F /* EZBingLanguageVoice.m */, + 030DB2602B56CC6500E27DEA /* BingLanguageVoice.swift */, 03F639932AA6CFBB009B9914 /* EZBingConfig.h */, 03F639942AA6CFBB009B9914 /* EZBingConfig.m */, ); @@ -2586,7 +2584,6 @@ 03991158292927E000E1B06D /* EZTitlebar.m in Sources */, 03D8A65C2A433B4100D9A968 /* EZConfiguration+EZUserData.m in Sources */, 03BD282229486CF200F5891A /* EZBlueTextButton.m in Sources */, - 037BEFCD2A98FDF700D0F17F /* EZBingLanguageVoice.m in Sources */, 03BDA7C22A26DA280079D04F /* NSString+Indenter.m in Sources */, 03542A462937B4C300C34C33 /* EZBaiduTranslateResponse.m in Sources */, 0309E1F0292B4A5E00AFB76A /* NSView+EZGetViewController.m in Sources */, @@ -2722,6 +2719,7 @@ 0333FDA62A035D5700891515 /* NSString+EZChineseText.m in Sources */, 03E02A222924E77100A10260 /* EZMenuItemManager.m in Sources */, 039D119929D5E26300C93F46 /* EZAudioUtils.m in Sources */, + 030DB2612B56CC6500E27DEA /* BingLanguageVoice.swift in Sources */, EA9943F22B5358BF00EE7B97 /* LanguageExtensions.swift in Sources */, 03B0231729231FA6001C7E63 /* Snip.m in Sources */, 03BFFC6E295FE59C004E033E /* EZQueryResult+EZYoudaoDictModel.m in Sources */, diff --git a/Easydict/Feature/Service/Bing/BingLanguageVoice.swift b/Easydict/Feature/Service/Bing/BingLanguageVoice.swift new file mode 100644 index 000000000..3751e9433 --- /dev/null +++ b/Easydict/Feature/Service/Bing/BingLanguageVoice.swift @@ -0,0 +1,26 @@ +// +// BingLanguageVoice.swift +// Easydict +// +// Created by Jerry on 2023-10-14. +// Copyright © 2023 izual. All rights reserved. +// + +import Foundation + +// Docs: https://learn.microsoft.com/zh-cn/azure/ai-services/speech-service/language-support?tabs=tts + +@objc(EZBingLanguageVoice) +class BingLanguageVoice: NSObject { + @objc var lang: String // BCP-47, en-US + @objc var voiceName: String // en-US-JennyNeural + + init(lang: String, voiceName: String) { + self.lang = lang + self.voiceName = voiceName + } + + @objc class func voice(withLanguage language: String, voiceName: String) -> BingLanguageVoice { + BingLanguageVoice(lang: language, voiceName: voiceName) + } +} diff --git a/Easydict/Feature/Service/Bing/EZBingLanguageVoice.h b/Easydict/Feature/Service/Bing/EZBingLanguageVoice.h deleted file mode 100644 index 2a193cbbd..000000000 --- a/Easydict/Feature/Service/Bing/EZBingLanguageVoice.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// EZBingTTSVoice.h -// Easydict -// -// Created by tisfeng on 2023/8/25. -// Copyright © 2023 izual. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -// Docs: https://learn.microsoft.com/zh-cn/azure/ai-services/speech-service/language-support?tabs=tts - -@interface EZBingLanguageVoice : NSObject - -@property (nonatomic, copy) NSString *lang; // BCP-47, en-US -@property (nonatomic, copy) NSString *voiceName; // en-US-JennyNeural - -+ (instancetype)voiceWithLanguage:(NSString *)langauge voiceName:(NSString *)voiceName; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Easydict/Feature/Service/Bing/EZBingLanguageVoice.m b/Easydict/Feature/Service/Bing/EZBingLanguageVoice.m deleted file mode 100644 index 4ba73a88d..000000000 --- a/Easydict/Feature/Service/Bing/EZBingLanguageVoice.m +++ /dev/null @@ -1,20 +0,0 @@ -// -// EZBingTTSVoice.m -// Easydict -// -// Created by tisfeng on 2023/8/25. -// Copyright © 2023 izual. All rights reserved. -// - -#import "EZBingLanguageVoice.h" - -@implementation EZBingLanguageVoice - -+ (instancetype)voiceWithLanguage:(NSString *)langauge voiceName:(NSString *)voiceName { - EZBingLanguageVoice *voice = [[EZBingLanguageVoice alloc] init]; - voice.lang = langauge; - voice.voiceName = voiceName; - return voice; -} - -@end diff --git a/Easydict/Feature/Service/Bing/EZBingRequest.m b/Easydict/Feature/Service/Bing/EZBingRequest.m index 3d6849b35..512e31b87 100644 --- a/Easydict/Feature/Service/Bing/EZBingRequest.m +++ b/Easydict/Feature/Service/Bing/EZBingRequest.m @@ -8,8 +8,8 @@ #import "EZBingRequest.h" #import "EZError.h" -#import "EZBingLanguageVoice.h" #import "NSString+EZRegex.h" +#import "Easydict-Swift.h" static NSString *const kAudioMIMEType = @"audio/mpeg"; static NSString *const kBingConfigKey = @"kBingConfigKey";