user2961688
user2961688

Reputation: 31

How to get single input from multiple audio input source

I have a direct input box with 2 input channels. Using getUserMedia, how can I specify to stream from the first or second input from the device? I've seen how to get the device specifically by feeding in the deviceId, but it gets both inputs mixed together.

Upvotes: 1

Views: 315

Answers (1)

Brad
Brad

Reputation: 163602

It sounds like you have a 2-channel audio interface. The MediaStream you get from getUserMedia() will contain both channels, as that's what's coming from the source. Therefore, you can't select just one of the streams initially.

However, you can easily split out the audio you want with the ChannelSplitterNode:

const splitter = audioContext.createChannelSplitter(2); // 2 channels
mediaStreamSourceNode.connect(splitter);
splitter.connect(targetForFirstChannel, 0);
splitter.connect(targetForSecondChannel, 1);

The second parameter of splitter.connect() sets the index of the output you want to use.

Upvotes: 1

Related Questions