使用libjingle的Android WebRTC中的自定义音频设备

时间:2018-09-16 13:39:28

标签: android audio webrtc libjingle

我正在开发本机android WebRTC客户端,该客户端支持从自定义设备流式传输音频(我正在从该设备通过蓝牙获取音频流)。我正在使用libjingle库来实现WebRTC,我想知道是否以及如何将自定义音频流连接到音轨?

当前,我正在添加默认音轨,如下所示:

localMS = factory.createLocalMediaStream("ARDAMS");

AudioSource audioSource = factory.createAudioSource(new MediaConstraints());
localMS.addTrack(factory.createAudioTrack("ARDAMSa0", audioSource));

我看到有WebRtcAuidioRecord(https://github.com/pristineio/webrtc-android/blob/master/libjingle_peerconnection/src/main/java/org/webrtc/voiceengine/WebRtcAudioRecord.java)-是否可以覆盖它?

有人尝试这样做吗?

1 个答案:

答案 0 :(得分:0)

您的帖子将我带到下面的代码,我将尝试一下,并让我知道它是否可以正常工作。我正在尝试将一个音频流发送到Watson API,将一个音频流发送到WebRTC,但是Android仅允许一个InputStream读取麦克风。如果我可以使用,我会及时更新。

private org.webrtc.MediaStream createMediaStream() {
    org.webrtc.MediaStream mediaStream = mFactory.createLocalMediaStream(ARDAMS);

    if (mEnableVideo) {
        mVideoCapturer = createVideoCapturer();
        if (mVideoCapturer != null) {
            mediaStream.addTrack(createVideoTrack(mVideoCapturer));
        } else {
            mEnableVideo = false;
        }
    }

    if (mEnableAudio) {
        createAudioCapturer();
        mediaStream.addTrack(mFactory.createAudioTrack(
                AUDIO_TRACK_ID,
                mFactory.createAudioSource(mAudioConstraints)));
    }

    return mediaStream;
}

/**
 * Creates a instance of WebRtcAudioRecord.
 */
private void createAudioCapturer() {
    if (mOption.getAudioType() == PeerOption.AudioType.EXTERNAL_RESOURCE) {
        WebRtcAudioRecord.setAudioRecordModuleFactory(new WebRtcAudioRecordModuleFactory() {
            @Override
            public WebRtcAudioRecordModule create() {
                AudioCapturerExternalResource module = new AudioCapturerExternalResource();
                module.setUri(mOption.getAudioUri());
                module.setSampleRate(mOption.getAudioSampleRate());
                module.setBitDepth(mOption.getAudioBitDepth());
                module.setChannel(mOption.getAudioChannel());
                return module;
            }
        });
    } else {
        WebRtcAudioRecord.setAudioRecordModuleFactory(null);
    }
}

来源: https://www.programcreek.com/java-api-examples/?code=DeviceConnect/DeviceConnect-Android/DeviceConnect-Android-master/dConnectDevicePlugin/dConnectDeviceWebRTC/app/src/main/java/org/deviceconnect/android/deviceplugin/webrtc/core/MediaStream.java