CNLiveChatVoiceMessage.h 1.83 KB
//
//  CNLiveChatVoiceMessage.h
//  CNLiveChatManagerSDKDemo
//
//  Created by cnliveJunBo on 17/7/12.
//  Copyright © 2017年 cnlive. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CNLiveChatStatusDefine.h"
#import "CNLiveChatUserInfo.h"

@interface CNLiveChatVoiceMessage : NSObject

/*!
 wav格式的音频数据
 */
@property(nonatomic, strong) NSData *wavAudioData;

/*!
 语音消息的时长
 */
@property(nonatomic, assign) long duration;

/*!
 语音消息的附加信息
 */
@property(nonatomic, strong) NSString *extra;

// * 基础属性 *
/**
 会话类型(私聊 / 聊天室)
 */
@property (nonatomic, assign) CNLiveConversationType conversationType;

/**
 目标ID(消息来自聊天室的ID / 接收者ID)
 */
@property (nonatomic, copy) NSString *targetId;

/**
 消息ID(本地存储的消息的唯一值(数据库索引唯一值))
 */
@property (nonatomic, copy) NSString *messageId;

/**
 发送者的用户信息(userId, name, portraitUri)
 */
@property (nonatomic, strong) CNLiveChatUserInfo *userInfo;

/*!
 初始化语音消息
 
 @param audioData   wav格式的音频数据
 @param duration    语音消息的时长(单位:秒)
 @return            语音消息对象
 
 @discussion
 如果您不是使用IMKit中的录音功能,则在初始化语音消息的时候,需要确保以下几点。
 1. audioData必须是单声道的wav格式音频数据;
 2. audioData的采样率必须是8000Hz,采样位数(精度)必须为16位。
 
 您可以参考的录音参数:
 NSDictionary *settings = @{AVFormatIDKey: @(kAudioFormatLinearPCM),
 AVSampleRateKey: @8000.00f,
 AVNumberOfChannelsKey: @1,
 AVLinearPCMBitDepthKey: @16,
 AVLinearPCMIsNonInterleaved: @NO,
 AVLinearPCMIsFloatKey: @NO,
 AVLinearPC'MIsBigEndianKey: @NO};
 */
+ (instancetype)messageWithAudio:(NSData *)audioData duration:(long)duration;

@end