
# 音频管理
#### enableLocalAudioStream
```
virtual int enableLocalAudioStream(bool enabled)
```
【**功能说明**】
设置是否开启本地麦克风音频采集。
【**请求参数**】
enable：true表示开启。false表示关闭。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 默认开启本地音频采集。

- 远端用户会收到[onRemoteAudioStateChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0107.html#rtc_05_0107__zh-cn_topic_0277015530_section9856611239)远端流状态变化回调。
 
 #### adjustRecordingVolume
```
virtual int adjustRecordingVolume(unsigned int volume)
```
【**功能说明**】
设置麦克风采集的音量。
【**请求参数**】
volume：范围为\[0-100\]，其中10表示原始音量。
【**返回参数** 】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
不影响系统音量。
 #### adjustPlaybackVolume
```
virtual int adjustPlaybackVolume(unsigned int volume)
virtual int adjustPlaybackVolume(const char* userId, unsigned int volume)
```
【**功能说明**】
设置扬声器播放的音量。
【**请求参数**】
volume：范围为\[0-100\]，其中10表示原始音量。
userId：用户ID。带用户ID表示设置单个用户的软（信号）音量。
【**返回参数** 】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
不影响系统音量。
 #### setShareComputerSound
```
virtual int setShareComputerSound(bool enable)
```
【**功能说明**】
设置是否开启系统音频采集、发送。只能在房间内使用。
【**请求参数**】
enable：true表示开启系统音频采集、发送。false表示关闭系统音频采集、发送。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
开启系统音频采集发送，会采集和发送当前系统所有音频。
 #### muteLocalAudio
```
virtual int muteLocalAudio(bool mute)
```
【**功能说明**】
设置是否关闭本地音频流发送。
【**请求参数**】
mute：true表示关闭本地音频发流。false表示开启本地音频发流。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 默认开启本地音频发流。
- 关闭本地音频发流，不影响本地音频采集。
- 远端用户会收到[onRemoteAudioStateChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0107.html#rtc_05_0107__zh-cn_topic_0277015530_section9856611239)远端流状态变化回调。
 
 #### muteRemoteAudio
```
virtual int muteRemoteAudio(const char* userId, bool mute)
```
【**功能说明**】
设置是否接收对应远端用户的音频流。同一时间所有房间最多只能接收17路音频流。
【**请求参数**】
- userId: 远端用户的userId，唯一标识。
- mute：true表示取消音频流接收。false表示开启音频流接收。默认为false。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 一般不需要接收自己的音频流，否则本端听筒里会听到自己说话的声音。
- TopN模式下，不支持此接口。
 
 #### muteAllRemoteAudio
```
virtual int muteAllRemoteAudio(bool mute)
```
【**功能说明**】
设置是否接收当前房间所有用户的音频流。
【**请求参数**】
mute：true表示取消接收，false表示开启接收。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 取消所有音频流接收，同时也会取消接收新加入用户的音频流。
- 开启所有音频流接收，同时也会开启接收新加入用户的音频流。
- 默认开启所有音频流接收。
- 不支持TopN模式。
 
 #### enableUserVolumeNotify
```
virtual int enableUserVolumeNotify(unsigned int interval)
```
【**功能说明**】
指定音量提示的时间间隔， 设置后按时间间隔触发回调，用户音量回调[onUserVolumeStatsNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0107.html#rtc_05_0107__zh-cn_topic_0277015530_section924462264812)。
【**请求参数**】
- interval：音量值上报周期，默认关闭音量回调。
  - 0：关闭音量回调。
  
  - \[100，10000\]：有效值范围，单位为毫秒。默认值为2000ms，建议设置为默认值2000ms。
   
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
 #### setSpeakerModel
```
virtual int setSpeakerModel(HRTCSpeakerModel speakerModel)
```
【**功能说明**】
设置声音播放模式。成功加入房间后调用。
【**请求参数**】
speakerModel：声音播放模式（耳机/扬声器），具体请参见[HRTCSpeakerModel](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__zh-cn_topic_0277015533_section826383016206)。
【**返回参数** 】
- 0：方法调用成功。
- \>0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
 #### enableAudioTNR
```
virtual int enableAudioTNR(HRTCAudioTnrMode mode)
```
【**功能说明**】
设置是否开启音频降噪。
【**请求参数**】
mode：表示上行降噪能力的档位。具体请参见HRTCAudioTnrMode
【**返回参数** 】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
 #### sendAudioSeiMsg
```
virtual int sendAudioSeiMsg(const char* message, unsigned int msglen, unsigned int repeateCount)
```
【**功能说明**】
发送音频SEI消息。通过音频SEI可将自定义信息嵌入到音频流中，发送给其他用户。
【**请求参数**】
message：发送的内容。长度为1-500字节。
msglen : 发送内容的字节数。
repeateCount：发送次数（1-10）。根据需要填发送次数，一般发1次。
【**返回参数**】
- 0：方法调用成功。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0080.html)。
 
 #### echoTest
```
virtual int echoTest(int intervalInSeconds)
```
【**功能说明**】
开始语音通话回路测试。房间外调用，要等测试结束后才能加入房间。
【**请求参数**】
intervalInSeconds：当前只能设置为-1。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
 #### finishEchoTest
```
virtual int finishEchoTest()
```
【**功能说明**】
停止语音通话回路测试。房间外调用。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
 #### setDefaultSpeakerModel
```
public abstract int setDefaultSpeakerModel(HRTCSpeakerModel speakerModel)
```
【**功能说明**】
设置默认的声音播放模式，在房间外调用。
【**请求参数**】
speakerModel：声音播放模式，具体请参见[HRTCSpeakerModel](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section162571531174117)。默认值为HRTC_SPEAKER_MODEL_SPEAKER。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
#### getAudioClipsVolume
```
virtual int getAudioClipsVolume()
```
【**功能说明**】
获取音效总音量。
【**请求参数**】
无
【**返回参数**】
- \>=0：音量大小,范围0-100。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
音效文件支持同时播放多个，[setAudioClipsVolume]接口设置的音量是所有音频文件的最大音量，[setVolumeOfAudioClip]接口设置的是单个音效文件的音量，音效文件的实际播放音量 = 最大音量 \* 自身音量 / 100。例如，最大音量是50，单个音效音量是80，实际播放音量就是50 \* 80 / 100 = 40
 #### setAudioClipsVolume
```
virtual int setAudioClipsVolume(double volume)
```
【**功能说明**】
设置音效总音量。
【**请求参数**】
volume：音量值大小，范围为0-100。
【**返回参数**】
- 0：方法调用成功。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
#### getVolumeOfAudioClip
```
virtual int getVolumeOfAudioClip(int soundId)
```
【**功能说明**】
获取指定音效的播放音量。
【**请求参数**】
soundId：音效ID，取值\>=0。
【**返回参数**】
- \>=0：音量大小，范围为0-100。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
音效文件支持同时播放多个，[setAudioClipsVolume]接口设置的音量是所有音频文件的最大音量，[setVolumeOfAudioClip]接口设置的是单个音效文件的音量，音效文件的实际播放音量 = 最大音量 \* 自身音量 / 100。例如，最大音量是50，单个音效音量是80，实际播放音量就是50 \* 80 / 100 = 40
 #### setVolumeOfAudioClip
```
virtual int setVolumeOfAudioClip(int soundId, double volume)
```
【**功能说明**】
设置指定音效音量。
【**请求参数**】
- soundId：音效ID，取值\>=0。
- volume：音量大小，范围为0-100。
【**返回参数**】
- 0：方法调用成功。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
#### playAudioClip
```
virtual int playAudioClip(int soundId, const char *filePath,int loop, double pitch, double pan, double gain, int publish, int startPos)
```
【**功能说明**】
播放音效文件并启动混音，需要在有joiner加入房间后调用。
【**请求参数**】
- soundId：音效ID，取值\>=0。
- filePath：音效文件路径，支持本地文件和网络文件。
- loop：音效文件播放次数，0为不播放，-1为循环播放。
- pitch：音调大小，当前不支持。
- pan：空间位置，当前不支持。
- gain：音量大小，取值范围为0-100。
- publish：1表示将音效文件混音后发送到远端，0表示本地播放，不发送到远端。
- startPos：起始播放位置，单位为ms。
【**返回参数**】
- 0：方法调用成功。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
soundId需要开发者自己生成并维护，保证不同的soundId对应不同的音效播放实例。同时音效播放完毕或者停止播放后，soundId最好主动回收，下一次播放音效的时候，尽量复用被回收的soundId。
#### stopAudioClip
```
virtual int stopAudioClip(int soundId)
```
【**功能说明**】
停止播放指定的音效文件。
【**请求参数**】
soundId：音效ID，取值\>=0。
【**返回参数**】
- 0：方法调用成功。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
 #### stopAllAudioClips
```
virtual int stopAllAudioClips()
```
【**功能说明**】
停止播放所有音效文件。
【**请求参数**】
无
【**返回参数**】
- 0：方法调用成功。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
 #### pauseAudioClip
```
virtual int pauseAudioClip(int soundId)
```
【**功能说明**】
暂停播放指定的音效文件。
【**请求参数**】
soundId：音效ID，取值\>=0。
【**返回参数**】
- 0：方法调用成功。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
 #### pauseAllAudioClips
```
virtual int pauseAllAudioClips()
```
【**功能说明**】
暂停播放所有音效文件。
【**请求参数**】
无
【**返回参数**】
- 0：方法调用成功。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
#### resumeAudioClip
```
virtual int resumeAudioClip(int soundId)
```
【**功能说明**】
暂停播放指定的音效文件。
【**请求参数**】
soundId：音效ID，取值\>=0。
【**返回参数**】
- 0：方法调用成功。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
 #### resumeAllAudioClips
```
virtual int resumeAllAudioClips()
```
【**功能说明**】
恢复播放所有音效文件。
【**请求参数**】
无
【**返回参数**】
- 0：方法调用成功。
- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
#### getAudioClipCurrentPosition
```
virtual int getAudioClipCurrentPosition(int soundId)
```
【**功能说明**】
获取指定音效文件当前的播放位置。
【**请求参数**】
soundId：音效ID，取值\>=0。
【**返回参数**】
- \>= 0：播放位置，单位为ms。

- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
#### setAudioClipPosition
```
virtual int setAudioClipPosition(int soundId, int pos)
```
【**功能说明**】
设置指定音效文件的播放位置。
【**请求参数**】
- soundId：音效ID，取值\>=0。
- pos：播放位置，单位为ms。
【**返回参数**】
- 0：方法调用成功。

- \< 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
#### getAudioClipDuration
```
virtual int getAudioClipDuration(const char *filePath)
```
【**功能说明**】
获取音效的文件时长。
【**请求参数**】
filePath：音效文件路径，支持本地文件和网络文件。
【**返回参数**】
- \> 0：音效文件时长，单位为ms。

- \<= 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
 #### setAudioFrameRecordParameters
```
public abstract int setAudioFrameRecordParameters(int sampleRate, int channel, HRTCAudioOperateMode mode, int samplesPerCall);
```
【**功能说明**】
设置采集回调参数，配合setAudioFrameObserver的onAudioFrameRecord使用。
【**请求参数**】
- sampleRate：onAudioFrameRecord中返回的采样率，可设置为8000，16000，32000, 44100， 48000。
- channel：声道，1表示单声道，2表示双声道。
- mode：可读可写模式，具体请参见[HRTCAudioOperateMode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section13549145211432)。
- samplesPerCall：每次回调的单声道样点数（小于(sampleRate/100)\*channel\*2\*3, 大于(sample/(100\*3))\*channel\*2）。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0080.html)。
 
