stream from server to browser an endless set of new input wav audio files
scottstensland opened this issue · 2 comments
to handle an upstream process which is synthesizing wav audio on server side which need to get rendered as audio on browser ... lets look at nodejs stream pipes
now building a new project so yes I'm in the same boat ... ping me github.com/scottstensland/websockets-streaming-audio
at Streaming audio through WebSockets to Web Audio player
- Produces audio on a server in to a 1 second WAV file
- Reads the WAV file and sends it through a websocket
AudioWorkletNode
can be substituted for AudioContext.decodeAudioData()
and AudioBufferSourceNode
at
- Websocket sends the binary data to AudioContext.decodeAudioData
- Decoded audio is buffered until 4 packets (4 seconds)
- Buffer is processed and sent to AudioBufferSourceNode.start(time) where time = (clip_count * duration)
to avoid memory consumption issues. The implementations might be different at Chromium or Chrome and Firefox or Nightly. Nightly does not currently implement ReadableStream.pipeTo()
,
FWIW see
- WebAudio/web-audio-api-v2#61
- w3c/media-source#55 (comment)
- https://github.com/AnthumChris/fetch-stream-audio/issues/2
Two versions of the code so far, tested at Chromium 81 and 82 launched with --enable-experimental-web-platform-features
flag
Note, the code at https://github.com/guest271314/AudioWorkletStream/blob/master/audioWorklet.js was conceived of and is written to handle an infinite input stream of WAV file(s) or binary data capable of being converted to Float32Array
's without a WAV header https://github.com/guest271314/AudioWorkletStream/blob/master/audioWorklet.js#L55.
Would suggest to process the input data at the server, if possible, to stream Float32Array
s having length
set to exactly 128
, save for the last part of the file, unless the stream is infinite, in which case the input read by WebSocket
at client should always be Float32Array
with length
set to 128
.