简体   繁体   English

如何从浏览器到 S3 的 stream 麦克风音频

[英]how to stream microphone audio from browser to S3

I want to stream the microphone audio from the web browser to AWS S3.我想 stream 麦克风音频从 web 浏览器到 AWS S3。 Got it working成功了

this.recorder = new window.MediaRecorder(...);
this.recorder.addEventListener('dataavailable', (e) => {
  this.chunks.push(e.data);
});

and then when user clicks on stop upload the chunks new Blob(this.chunks, { type: 'audio/wav' }) as multiparts to AWS S3.然后当用户单击停止将块new Blob(this.chunks, { type: 'audio/wav' })作为多部分上传到 AWS S3 时。

But the problem is if the recording is 2-3 hours longer then it might take exceptionally longer and user might close the browser before waiting for the recording to complete uploading.但问题是,如果录制时间长 2-3 小时,那么它可能需要特别长的时间,并且用户可能会在等待录制完成上传之前关闭浏览器。

Is there a way we can stream the web audio directly to S3 while it's going on?有没有办法在 S3 进行时将 stream web 音频直接发送到 S3?

Things I tried but can't get a working example:我尝试过但无法获得工作示例的事情:

  1. Kineses video streams, looks like it's only for real time streaming between multiple clients and I have to write my own client which will then save it to S3. Kines 视频流,看起来它只适用于多个客户端之间的实时流,我必须编写自己的客户端,然后将其保存到 S3。
  2. Thought to use kinesis data firehose but couldn't find any client data producer from brower.想使用 kinesis data firehose 但无法从浏览器中找到任何客户端数据生成器。
  3. Even tried to find any resource using aws lex or aws ivs but I think they are just over engineering for my use case.甚至尝试使用 aws lex 或 aws ivs 查找任何资源,但我认为它们对我的用例来说只是过度工程。

Any help will be appreciated.任何帮助将不胜感激。

You can set the timeslice parameter when calling start() on the MediaRecorder .您可以在调用timeslice上的MediaRecorder start()时设置时间片参数。 The MediaRecorder will then emit chunks which roughly match the length of the timeslice parameter.然后MediaRecorder将发出与timeslice参数的长度大致匹配的块。

You could upload those chunks using S3's multipart upload feature as you already mentioned.正如您已经提到的,您可以使用 S3 的分段上传功能上传这些块。

Please note that you need a library like extendable-media-recorder if you want to record a WAV file since no browser supports that out of the box.请注意,如果你想录制 WAV 文件,你需要一个像extendable-media-recorder这样的库,因为没有浏览器直接支持它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM