forked from iosre/WeChatRobotForExample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWCRVoiceProcessor.m
69 lines (57 loc) · 1.35 KB
/
WCRVoiceProcessor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#import "WCRGlobalHeader.h"
static WCRVoiceProcessor *sharedProcessor;
@implementation WCRVoiceProcessor
@synthesize voiceToTextCallback;
@synthesize voiceDownloadInfo;
@synthesize helper;
@synthesize lastVoiceID;
+ (void)initialize
{
if (self == [WCRVoiceProcessor class]) sharedProcessor = [[self alloc] init];
}
- (instancetype)init
{
if (self = [super init])
{
#if !__has_feature(objc_arc)
[voiceDownloadInfo release];
#endif
voiceDownloadInfo = nil;
voiceDownloadInfo = [@{} mutableCopy];
}
return self;
}
+ (instancetype)sharedProcessor
{
return sharedProcessor;
}
- (void)convertVoiceWrap:(CMessageWrap *)wrap completion:(VoiceToTextCallback)completion
{
@autoreleasepool
{
VoiceTransFloatPreview *preview = [[objc_getClass("VoiceTransFloatPreview") alloc] init];
NSString *voiceID = [preview getVoiceIDFromMsg:wrap];
self.helper = nil;
self.helper = [[objc_getClass("VoiceTransHelper") alloc] initWithVoiceMsg:wrap VoiceID:voiceID];
[self.helper startVoiceTrans];
#if !__has_feature(objc_arc)
[preview release];
#endif
preview = nil;
self.voiceToTextCallback = nil;
self.voiceToTextCallback = completion;
}
}
#if !__has_feature(objc_arc)
- (void)dealloc
{
[lastVoiceID release];
lastVoiceID = nil;
[helper release];
helper = nil;
[voiceDownloadInfo release];
voiceDownloadInfo = nil;
[super dealloc];
}
#endif
@end