NIMMediaManagerProtocol.h
6.24 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
//
// NIMMediaManagerProtocol.h
// NIMLib
//
// Created by Netease.
// Copyright (c) 2015年 Netease. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* 音频输出设备类型
*/
typedef NS_ENUM(NSInteger, NIMAudioOutputDevice){
/**
* 听筒
*/
NIMAudioOutputDeviceReceiver,
/**
* 扬声器
*/
NIMAudioOutputDeviceSpeaker
};
/**
* 云信支持的音频类型
*/
typedef NS_ENUM(NSInteger, NIMAudioType) {
/**
* aac
*/
NIMAudioTypeAAC,
/**
* amr
*/
NIMAudioTypeAMR
};
/**
* 语音转文字
*
* @param error 执行结果,如果成功error为nil
* @prarm text 转换后的文本
*/
typedef void(^NIMAudioToTextBlock)(NSError * __nullable error,NSString * __nullable text);
/**
* 语音转文字选项
*/
@interface NIMAudioToTextOption : NSObject
/**
* 音频URL
* @discussion 目前只支持云信服务器的URL,不支持外链
*/
@property (nonatomic,copy) NSString *url;
/**
* 音频本地地址
* @discussion APP需要保证音频已经下载到本地
*/
@property (nonatomic,copy) NSString *filepath;
@end
/**
* 多媒体委托
*/
@protocol NIMMediaManagerDelegate <NSObject>
@optional
/**
* 开始播放音频的回调
*
* @param filePath 音频文件路径
* @param error 错误信息
*/
- (void)playAudio:(NSString *)filePath didBeganWithError:(nullable NSError *)error;
/**
* 播放完音频的回调
*
* @param filePath 音频文件路径
* @param error 错误信息
*/
- (void)playAudio:(NSString *)filePath didCompletedWithError:(nullable NSError *)error;
/**
* 播放音频开始被打断回调
*/
- (void)playAudioInterruptionBegin;
/**
* 播放音频结束被打断回调
*/
- (void)playAudioInterruptionEnd;
/**
* 开始录制音频的回调
*
* @param filePath 录制的音频的文件路径
* @param error 错误信息
* @discussion 如果录音失败,filePath 有可能为 nil
*/
- (void)recordAudio:(nullable NSString *)filePath didBeganWithError:(nullable NSError *)error;
/**
* 录制音频完成后的回调
*
* @param filePath 录制完成的音频文件路径
* @param error 错误信息
*/
- (void)recordAudio:(nullable NSString *)filePath didCompletedWithError:(nullable NSError *)error;
/**
* 录音被取消的回调
*/
- (void)recordAudioDidCancelled;
/**
* 音频录制进度更新回调
*
* @param currentTime 当前录制的时间
*/
- (void)recordAudioProgress:(NSTimeInterval)currentTime;
/**
* 录音开始被打断回调
*/
- (void)recordAudioInterruptionBegin;
/**
* 录音结束被打断回调
*/
- (void)recordAudioInterruptionEnd;
@end
/**
* 多媒体控制协议
*/
@protocol NIMMediaManager <NSObject>
@required
/**
* 录音进度更新间隔
* @discussion 如果值大于0,则会按照相应间隔调用recordAudioProgress:回调,默认值为0.3
*/
@property (nonatomic, assign) NSTimeInterval recordProgressUpdateTimeInterval;
#pragma mark - play audio
/**
* 切换音频输出设备
*
* @param outputDevice 音频输出设备
*
* @return 是否切换成功
*/
- (BOOL)switchAudioOutputDevice:(NIMAudioOutputDevice)outputDevice;
/**
* 在播放声音的时候,如果手机贴近耳朵,是否需要自动切换成听筒播放
*
* @param needProximityMonitor 是否需要贴耳传感器监听
*/
- (void)setNeedProximityMonitor:(BOOL)needProximityMonitor;
/**
* 是否正在播放音频
*
*/
- (BOOL)isPlaying;
/**
* 播放音频文件
*
* @discussion 开始播放,NIMMediaManagerDelegate中的playAudio:didBeganWithError:回调会被触发,播放完成后, NIMMediaManagerDelegate中的playAudio:didCompletedWithError:回调会被触发
* @param filepath 音频文件路径
*/
- (void)play:(NSString *)filepath;
/**
* 停止播放音频
*
* @discussion 音频播放完成后NIMMediaManagerDelegate中的playAudio:didCompletedWithError:回调会被触发
*/
- (void)stopPlay;
/**
* 设置播放音频的起始时间
* @param timestamp 起始时间
* @discussion 起始时间不能大于整个音频的时间,否则播放无效。调用此方法后,不需要再调用 play: 方法,自动播放
*/
- (BOOL)seek:(NSTimeInterval)timestamp;
#pragma mark - record audio
/**
* 是否正在录音
*
*/
- (BOOL)isRecording;
/**
* 开始录制音频
*
* @param duration 最长录音时间
* @discussion 开始录音,NIMMediaManagerDelegate中的recordAudio:didBeganWithError:回调会被触发,录音完成后, NIMMediaManagerDelgate中的recordAudio:didCompletedWithError:回调会被触发
* 默认使用 aac 编码格式
*/
- (void)recordForDuration:(NSTimeInterval)duration;
/**
* 开始录音
*
* @param type 音频类型
* @param duration 最大时长
* @discussion 开始录音,NIMMediaManagerDelegate中的recordAudio:didBeganWithError:回调会被触发,录音完成后, NIMMediaManagerDelegate中的recordAudio:didCompletedWithError:回调会被触发
*/
- (void)record:(NIMAudioType)type
duration:(NSTimeInterval)duration;
/**
* 停止录制音频
*
* @discussion 停止录音后NIMMediaManagerDelegate中的recordAudio:didCompletedWithError:回调会被触发
*/
- (void)stopRecord;
/**
* 取消录制音频
*
* @discussion 录音取消后,NIMMediaManagerDelegate中的recordAudioDidCancelled回调会被触发
*/
- (void)cancelRecord;
/**
* 获取录音分贝
*
*/
- (float)recordPeakPower;
/**
* 获取录音分贝
*
*/
- (float)recordAveragePower;
/**
* 语音转文字
*
* @param option 语音转文字选项
* @param result 完成回调
*/
- (void)transAudioToText:(NIMAudioToTextOption *)option
result:(NIMAudioToTextBlock)result;
#pragma mark - common setting
/**
* 设置录制或者播放完成以后是否自动deactivate AVAudioSession
*
* @param deactivate 是否deactivate,默认为YES
*/
- (void)setDeactivateAudioSessionAfterComplete:(BOOL)deactivate;
#pragma mark - delegates
/**
* 添加多媒体委托
*
* @param delegate 多媒体委托
*/
- (void)addDelegate:(id<NIMMediaManagerDelegate>)delegate;
/**
* 移除多媒体委托
*
* @param delegate 多媒体委托
*/
- (void)removeDelegate:(id<NIMMediaManagerDelegate>)delegate;
@end
NS_ASSUME_NONNULL_END