NIMSDK-iOS
载入中...
搜索中...
未找到
NIMMediaManagerProtocol.h
浏览该文件的文档.
1//
2// NIMMediaManagerProtocol.h
3// NIMLib
4//
5// Created by Netease.
6// Copyright (c) 2015年 Netease. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10
11NS_ASSUME_NONNULL_BEGIN
12
13/**
14 * 音频输出设备类型
15 */
16typedef NS_ENUM(NSInteger, NIMAudioOutputDevice){
17 /**
18 * 听筒
19 */
21 /**
22 * 扬声器
23 */
25};
26
27/**
28 * 云信支持的音频类型
29 */
30typedef NS_ENUM(NSInteger, NIMAudioType) {
31 /**
32 * aac
33 */
35 /**
36 * amr
37 */
39};
40
41
42/**
43 * 语音转文字
44 *
45 * @param error 执行结果,如果成功error为nil
46 * @prarm text 转换后的文本
47 */
48typedef void(^NIMAudioToTextBlock)(NSError * __nullable error,NSString * __nullable text);
49
50
51/**
52 * 语音转文字选项
53 */
54@interface NIMAudioToTextOption : NSObject
55
56/**
57 * 音频URL
58 * @discussion 目前只支持云信服务器的URL,不支持外链
59 */
60@property (nonatomic,copy) NSString *url;
61
62/**
63 * 音频本地地址
64 * @discussion APP需要保证音频已经下载到本地
65 */
66@property (nonatomic,copy) NSString *filepath;
67@end
68
69
70/**
71 * 多媒体委托
72 */
73@protocol NIMMediaManagerDelegate <NSObject>
74
75@optional
76
77/**
78 * 开始播放音频的回调
79 *
80 * @param filePath 音频文件路径
81 * @param error 错误信息
82 */
83- (void)playAudio:(NSString *)filePath didBeganWithError:(nullable NSError *)error;
84
85/**
86 * 播放完音频的回调
87 *
88 * @param filePath 音频文件路径
89 * @param error 错误信息
90 */
91- (void)playAudio:(NSString *)filePath didCompletedWithError:(nullable NSError *)error;
92
93/**
94 * 播放完音频的进度回调
95 *
96 * @param filePath 音频文件路径
97 * @param value 播放进度 0.0 - 1.0
98 */
99- (void)playAudio:(NSString *)filePath progress:(float)value;
100
101/**
102 * 停止播放音频的回调
103 *
104 * @param filePath 音频文件路径
105 * @param error 错误信息
106 */
107- (void)stopPlayAudio:(NSString *)filePath didCompletedWithError:(nullable NSError *)error;
108
109/**
110 * 播放音频开始被打断回调
111 */
112- (void)playAudioInterruptionBegin;
113
114/**
115 * 播放音频结束被打断回调
116 */
117- (void)playAudioInterruptionEnd;
118
119/**
120 * 开始录制音频的回调
121 *
122 * @param filePath 录制的音频的文件路径
123 * @param error 错误信息
124 * @discussion 如果录音失败,filePath 有可能为 nil
125 */
126- (void)recordAudio:(nullable NSString *)filePath didBeganWithError:(nullable NSError *)error;
127
128/**
129 * 录制音频完成后的回调
130 *
131 * @param filePath 录制完成的音频文件路径
132 * @param error 错误信息
133 */
134- (void)recordAudio:(nullable NSString *)filePath didCompletedWithError:(nullable NSError *)error;
135
136/**
137 * 录音被取消的回调
138 */
139- (void)recordAudioDidCancelled;
140
141/**
142 * 音频录制进度更新回调
143 *
144 * @param currentTime 当前录制的时间
145 */
146- (void)recordAudioProgress:(NSTimeInterval)currentTime;
147
148/**
149 * 录音开始被打断回调
150 */
151- (void)recordAudioInterruptionBegin;
152
153/**
154 * 录音结束被打断回调
155 */
156- (void)recordAudioInterruptionEnd;
157
158@end
159
160/**
161 * 多媒体控制协议
162 */
163@protocol NIMMediaManager <NSObject>
164
165@required
166
167/**
168 * 录音进度更新间隔
169 * @discussion 如果值大于0,则会按照相应间隔调用recordAudioProgress:回调,默认值为0.3
170 */
171@property (nonatomic, assign) NSTimeInterval recordProgressUpdateTimeInterval;
172
173/**
174 * 连接外接音频设备时是否仍使用内置麦克风,设置不做持久化,app运行周期有效
175 * @discussion 默认为NO,为NO时则跟随系统last in原则输入音频,为YES时则使用内置麦克风
176 */
177@property (nonatomic, assign) BOOL shouldUseBuiltInMic;
178
179#pragma mark - play audio
180/**
181 * 切换音频输出设备
182 *
183 * @param outputDevice 音频输出设备
184 *
185 * @return 是否切换成功
186 */
187- (BOOL)switchAudioOutputDevice:(NIMAudioOutputDevice)outputDevice;
188
189/**
190 * 在播放声音的时候,如果手机贴近耳朵,是否需要自动切换成听筒播放
191 *
192 * @param needProximityMonitor 是否需要贴耳传感器监听
193 */
194- (void)setNeedProximityMonitor:(BOOL)needProximityMonitor;
195
196
197/**
198 * 是否正在播放音频
199 *
200 */
201- (BOOL)isPlaying;
202
203/**
204 * 播放音频文件
205 *
206 * @discussion 开始播放,NIMMediaManagerDelegate中的playAudio:didBeganWithError:回调会被触发,播放完成后, NIMMediaManagerDelegate中的playAudio:didCompletedWithError:回调会被触发
207 * @param filepath 音频文件路径
208 */
209- (void)play:(NSString *)filepath;
210
211/**
212 * 停止播放音频
213 *
214 * @discussion 音频播放完成后NIMMediaManagerDelegate中的playAudio:didCompletedWithError:回调会被触发
215 */
216- (void)stopPlay;
217
218
219/**
220 * 设置播放音频的起始时间
221 * @param timestamp 起始时间
222 * @discussion 起始时间不能大于整个音频的时间,否则播放无效。调用此方法后,不需要再调用 play: 方法,自动播放
223 */
224- (BOOL)seek:(NSTimeInterval)timestamp;
225
226#pragma mark - record audio
227
228/**
229 * 是否正在录音
230 *
231 */
232- (BOOL)isRecording;
233
234/**
235 * 开始录制音频
236 *
237 * @param duration 最长录音时间
238 * @discussion 开始录音,NIMMediaManagerDelegate中的recordAudio:didBeganWithError:回调会被触发,录音完成后, NIMMediaManagerDelgate中的recordAudio:didCompletedWithError:回调会被触发
239 * 默认使用 aac 编码格式
240 */
241- (void)recordForDuration:(NSTimeInterval)duration;
242/**
243 * 开始录音
244 *
245 * @param type 音频类型
246 * @param duration 最大时长
247 * @discussion 开始录音,NIMMediaManagerDelegate中的recordAudio:didBeganWithError:回调会被触发,录音完成后, NIMMediaManagerDelegate中的recordAudio:didCompletedWithError:回调会被触发
248 */
249- (void)record:(NIMAudioType)type
250 duration:(NSTimeInterval)duration;
251
252/**
253 * 停止录制音频
254 *
255 * @discussion 停止录音后NIMMediaManagerDelegate中的recordAudio:didCompletedWithError:回调会被触发
256 */
257- (void)stopRecord;
258
259/**
260 * 取消录制音频
261 *
262 * @discussion 录音取消后,NIMMediaManagerDelegate中的recordAudioDidCancelled回调会被触发
263 */
264- (void)cancelRecord;
265
266/**
267 * 获取录音分贝
268 *
269 */
270- (float)recordPeakPower;
271
272/**
273 * 获取录音分贝
274 *
275 */
276- (float)recordAveragePower;
277
278
279/**
280 * 语音转文字
281 *
282 * @param option 语音转文字选项
283 * @param result 完成回调
284 */
285- (void)transAudioToText:(NIMAudioToTextOption *)option
286 result:(NIMAudioToTextBlock)result;
287
288
289#pragma mark - common setting
290
291/**
292 * 禁止在IM 录制、播放音频时设置AVAudioSession, 防止影响其他音视频效果
293 * @param disabled YES则禁止重置
294 */
295- (void)disableResetAudioSession:(BOOL)disabled;
296
297/**
298 * 设置录制或者播放完成以后是否自动deactivate AVAudioSession
299 *
300 * @param deactivate 是否deactivate,默认为YES
301 */
302- (void)setDeactivateAudioSessionAfterComplete:(BOOL)deactivate;
303
304#pragma mark - delegates
305/**
306 * 添加多媒体委托
307 *
308 * @param delegate 多媒体委托
309 */
310- (void)addDelegate:(id<NIMMediaManagerDelegate>)delegate;
311
312/**
313 * 移除多媒体委托
314 *
315 * @param delegate 多媒体委托
316 */
317- (void)removeDelegate:(id<NIMMediaManagerDelegate>)delegate;
318
319
320@end
321
322
323NS_ASSUME_NONNULL_END
NIMAudioType
Definition: NIMMediaManagerProtocol.h:30
@ NIMAudioTypeAAC
Definition: NIMMediaManagerProtocol.h:34
@ NIMAudioTypeAMR
Definition: NIMMediaManagerProtocol.h:38
NIMAudioOutputDevice
Definition: NIMMediaManagerProtocol.h:16
@ NIMAudioOutputDeviceReceiver
Definition: NIMMediaManagerProtocol.h:20
@ NIMAudioOutputDeviceSpeaker
Definition: NIMMediaManagerProtocol.h:24
void(^ NIMAudioToTextBlock)(NSError *__nullable error, NSString *__nullable text)
Definition: NIMMediaManagerProtocol.h:48
Definition: NIMMediaManagerProtocol.h:55
NSString * filepath
Definition: NIMMediaManagerProtocol.h:66
NSString * url
Definition: NIMMediaManagerProtocol.h:60