Web Audio Api: Proper way to play data chunks from a nodejs server via socket

前端 未结 2 1234
孤独总比滥情好
孤独总比滥情好 2021-01-03 10:03

I\'m using the following code to decode audio chunks from nodejs\'s socket

window.AudioContext = window.AudioContext || window.webkitAudioContext;
var contex         


        
相关标签:
2条回答
  • 2021-01-03 10:41

    You can take this code as an example: https://github.com/kmoskwiak/node-tcp-streaming-server

    It basically uses media source extensions. All you need to do is to change from video to audio

    buffer = mediaSource.addSourceBuffer('audio/mpeg');

    0 讨论(0)
  • 2021-01-03 10:54

    yes @Keyne is right,

    const mediaSource = new MediaSource()
    const sourceBuffer = mediaSource.addSourceBuffer('audio/mpeg')
    player.src = URL.createObjectURL(mediaSource)
    sourceBuffer.appendBuffer(chunk) // Repeat this for each chunk as ArrayBuffer
    player.play()
    

    But do this only if you don't care about IOS support

    0 讨论(0)
提交回复
热议问题