0

I am only able to broadcast audio alone using mic and speaker, and if I use setExternalAudioSource method, then the broadcast encounter with some heavy unwanted noise. I just want to broadcast the raw audio data alone without using mic, speaker and unwanted noise.

 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
    )

}

Is this possible using agora or is there any alternative to it?

4

1 回答 1

0

产生噪音的原因:

  1. 您的源音频 PCM 样本本身就很嘈杂
  2. 引擎错误
  3. 你设置的采样率不对

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

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

setParameters("{\"che.audio.override_apm\":true}")
于 2019-01-05T08:39:27.153 回答