天天看點

産品百科 | Ali RTC SDK 如何設定音頻屬性

音視訊通信 RTC(Real-Time Communication)是阿裡雲覆寫全球的實時音視訊開發平台,依托核心音視訊編解碼、信道傳輸、網絡排程技術,提供高可用、高品質、超低延時的音視訊通信服務,讓使用者快速搭建多端實時應用,适用于線上教育、視訊會議、互動娛樂、音視訊社交等場景。

産品連結:

https://www.aliyun.com/product/rtc 本文将為您介紹如何設定音質模式、音頻屬性。閱讀本文後,你可以根據實際業務需求設定音頻屬性,以達到更好的産品體驗。

功能簡介

AliRTC SDK 提供了三種音質模式和四種場景供您選擇,您可以針對自己的産品場景設定音頻屬性。比如,在語音電台場景下需要高品質的音質,您可以選擇高音質模式配合音樂場景實作高音質的需求。

音頻 Profile 規格

音頻 Profile 關鍵字 名稱 聲道數 / 采樣率 / 編碼碼率
ENGINE_LOW_QUALITY_MODE 低功耗音質模式 1/8kHz/12kbps
ENGINE_BASIC_QUALITY_MODE 标準音質模式(預設模式) 1/16kHz/24kbps
ENGINE_HIGH_QUALITY_MODE 高音質模式 1/48kHz/48kbps

音頻 scene 規格

場景關鍵字 特性
SCENE_DEFAULT_MODE 預設場景 推薦一般的音視訊通信場景使用。
SCENE_EDUCATION_MODE 教育場景 優先保證音頻連續性與穩定性。
SCENE_MEDIA_MODE 媒體場景 保真人聲與音樂音質,推薦連麥直播間使用。
SCENE_MUSIC_MODE 音樂場景 高保真音樂音質,推薦樂器教學等對音樂音質有要求的場景使用。

參數搭配推薦

說明 您可以根據推薦進行參數搭配,也可以根據自身實際業務場景進行自定義搭配。例如社交場景中,有背景音樂的音質需求,scene 可以選擇音樂場景,如果沒有背景音樂需求,scene 場景可以選擇預設背景。

業務場景 profile 設定 scene 設定
音視訊通話 标準音質模式(ENGINE_BASIC_QUALITY_MODE) 預設場景(SCENE_DEFAULT_MODE) 在保證高清音質的同時,保證傳輸穩定流暢。
音頻社交場景 高音質模式(ENGINE_HIGH_QUALITY_MODE) 音樂場景(SCENE_MUSIC_MODE) 高保真音樂音質,樂器教學等對音樂音質有要求的場景推薦使用。
音頻社交場景 2 高保真人聲,沒有背景音樂需求。
教育場景(SCENE_EDUCATION_MODE) 優先保證音頻連續性與穩定性,同時保證音質高清。

實作方法

Android、iOS、Mac 和 Windows SDK 平台關于音頻的 profile 設定與 scene 設定都是通過建立 AliRTCSDK 時傳遞的 extras 參數來設定,extras 參數形式在 SDK 平台是統一的(json 字元串),如下所示:

{"user_specified_ engine_mode" : "profile設定關鍵字","user_specified_scene_mode" :"scene場景關鍵字"}      

示例代碼

android

JSONObject jsonObject = new JSONObject();
//配置音質模式
try {
   jsonObject.put("user_specified_engine_mode", "ENGINE_BASIC_QUALITY_MODE");
   //配置場景模式
   jsonObject.put("user_specified_scene_mode", "SCENE_DEFAULT_MODE");
   AliRtcEngine aliRtcEngine = AliRtcEngine.getInstance(getApplicationContext(),jsonObject);
} catch (JSONException e) {
   e.printStackTrace();
}      

iOS

@property (nonatomic, strong) AliRtcEngine *engine;
NSMutableDictionary *extraDic = [[NSMutableDictionary alloc] init];
[extraDic setValue:@"ENGINE_BASIC_QUALITY_MODE" forKey:@"user_specified_engine_mode"];
[extraDic setValue:@"SCENE_EDUCATION_MODE" forKey:@"user_specified_scene_mode"];
NSError *error = nil;
NSData *json = [NSJSONSerialization dataWithJSONObject:extraDic options:NSJSONWritingPrettyPrinted error:&error];
NSString *string = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
_engine = [AliRtcEngine sharedInstance:self extras: string];      

Mac

@property (nonatomic, strong) AliRtcEngine *engine;
NSMutableDictionary *extraDic = [[NSMutableDictionary alloc] init];
[extraDic setValue:@"ENGINE_BASIC_QUALITY_MODE" forKey:@"user_specified_engine_mode"];
[extraDic setValue:@"SCENE_EDUCATION_MODE" forKey:@"user_specified_scene_mode"];
NSError *error = nil;
NSData *json = [NSJSONSerialization dataWithJSONObject:extraDic options:NSJSONWritingPrettyPrinted error:&error];
NSString *string = [[NSString alloc] initWithData:json encoding:NSUTF8StringEncoding];
_engine = [AliRtcEngine sharedInstance:self extras: string];      

Windows

std::string GetEngAndsceneMode(const std::string strEngMode, const std::string strSceneMode) 
{
  std::string strParam = "{";
  if (strEngMode == "default") 
  {
    strParam += "\"user_specified_engine_mode\" : \"ENGINE_BASIC_QUALITY_MODE\",";
  }
  if (strSceneMode == "default")
  {
    strParam += "\"user_specified_scene_mode\" : \"SCENE_DEFAULT_MODE\",";
  }
  strParam += "}";
  return strParam;
}
AliRtcEventListener* rtcEventlister;
std::string strEngMode = "default";
std::string strSceneMode = "default";
AliRtcEngine *mpEngine = AliRtcEngine::sharedInstance(rtcEventlister, GetEngAndsceneMode(strEngMode, strSceneMode).c_str());      

注意 示例代碼中 SDK 的初始化 extras 參數隻包含了音頻設定,實際代碼設定過程中,還可以包含其他子產品功能的初始化設定。

「視訊雲技術」你最值得關注的音視訊技術公衆号,每周推送來自阿裡雲一線的實踐技術文章,在這裡與音視訊領域一流工程師交流切磋。
産品百科 | Ali RTC SDK 如何設定音頻屬性

繼續閱讀