Skip to content

RTCAudioSource - Expected a .byteLength of 480, not 2770 #19

@royibernthal

Description

@royibernthal

I'm trying to have my nodejs backend act as a peer that streams pcm audio to the browser. (let's assume it's the only way to achieve what I need)

I'm creating an RTCAudioSource, and adding to it an array of chunked buffers - PCM 24k sample rate signed 16-bit little-endian.

RTCAudioSource/onData only accepts an Int16Array in samples, so I tried converting the buffers:

import { nonstandard } from '@roamhq/wrtc';

const source = new nonstandard.RTCAudioSource();

const samples = new Int16Array(
  buffer.buffer,
  buffer.byteOffset,
  buffer.byteLength / Int16Array.BYTES_PER_ELEMENT,
);

// adding a single chunk. in practice I'm adding many more chunks
// throws "Expected a .byteLength of 480, not x"
source.onData({
  samples,
  sampleRate: 24000,
  bitsPerSample: 16,
  channelCount: 1,
});

source.onData() throws the following error, with x being anywhere from 17 to 2770 depending on the chunk size:

Expected a .byteLength of 480, not x

It's worth noting that the PCM buffers play fine when writing them to a wav file or when emitting and playing them in the browser via web sockets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions