仅广播原始音频数据,不使用麦克风或扬声器



我只能使用麦克风和扬声器单独广播音频,如果我使用setExternalAudioSource方法,那么广播会遇到一些严重的不需要的噪音。我只想单独广播原始音频数据,而无需使用麦克风,扬声器和不必要的噪音。

 private val PERMISSION_REQ_ID_RECORD_AUDIO = 22
private var mRtcEngine: RtcEngine? = null// Tutorial Step 1
private val mRtcEventHandler = object : IRtcEngineEventHandler() { // Tutorial Step 1
    override fun onUserOffline(uid: Int, reason: Int) { // Tutorial Step 4
        //runOnUiThread { onRemoteUserLeft(uid, reason) }
    }
    override fun onUserMuteAudio(uid: Int, muted: Boolean) { // Tutorial Step 6
        // runOnUiThread { onRemoteUserVoiceMuted(uid, muted) }
    }
}
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    if (checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO)) {
        createRtcChannel()
    }
}
fun checkSelfPermission(permission: String, requestCode: Int): Boolean {
    if (ContextCompat.checkSelfPermission(this,
                    permission) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                arrayOf(permission),
                requestCode)
        return false
    }
    return true
}
private fun createRtcChannel() {
    initializeAgoraEngine()     // Tutorial Step 1
    joinChannel()
}
private fun initializeAgoraEngine() {
    try {
        mRtcEngine = RtcEngine.create(this, getString(R.string.agora_app_id), mRtcEventHandler)
        //set the channel as live broadcast mode
        mRtcEngine?.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING)
        mRtcEngine?.setClientRole(Constants.CLIENT_ROLE_BROADCASTER)
    } catch (e: Exception) {
    }
}
private fun joinChannel() {
    mRtcEngine?.joinChannel(null, "voiceDemoChannel1", "Extra Optional Data", 0) // if you do not specify the uid, we will generate the uid for you
    val payload = IOUtils.toByteArray(assets.openFd("ringtone.mp3").createInputStream())
    mRtcEngine?.setExternalAudioSource(
            true,      
            8000,     
            1     );
    mRtcEngine?.pushExternalAudioFrame(
            payload,
            1000
    )
}

使用集市是否可能这样做,或者还有其他选择吗?

可能导致噪音的原因:

  1. 源音频 PCM 样本本身就有噪音
  2. 引擎错误
  3. 您设置的采样率错误

对于第一个,您可以直接检查PCM示例。对于第二个,由于已经有很多人使用,所以很少是真的。因此,如果您确定源PCM样本良好,我建议您检查采样率。

此外,您可以在加入频道之前设置 APM 选项,以启用外部源的音频增强,方法是

setParameters("{"che.audio.override_apm":true}")

相关内容

  • 没有找到相关文章

最新更新