简体   繁体   English

如何保存 blob 并使用 wavesurfer 播放

[英]How to save blob and play it with wavesurfer

I'm creating a chat application where audio messages can be recorded.我正在创建一个可以记录音频消息的聊天应用程序。

I am creating blobs using react-mic.我正在使用 react-mic 创建 blob。 This is where i run into problems.这是我遇到问题的地方。

Can i just stringify the blob, save it to my DB and then pull it, reverse it and play it with Wavesurfer?我可以将 blob 字符串化,将其保存到我的数据库中,然后将其拉出、反转并与 Wavesurfer 一起播放吗?

Also I dont think i'm really thinking about this the right way, because the blob:URL is always a local host adress?另外我不认为我真的以正确的方式考虑这个问题,因为 blob:URL 始终是本地主机地址?

Use the "loadBlob" method to play the audio directly.使用“loadBlob”方法直接播放音频。

If you want to store the audio file for later use, simply add a reference URL in your db that points to the audio file within CDN.如果您想存储音频文件以供以后使用,只需在您的数据库中添加一个指向 CDN 中的音频文件的参考 URL。

Heres how my AudioPlayer component defines how to load the audioData下面是我的 AudioPlayer 组件如何定义如何加载 audioData

 wavesurfer.current = WaveSurfer.create(options);

  if (!audioData) return;

  if (typeof audioData === "string") {
    wavesurfer.current.load(audioData); // must be a URL
  } else {
    wavesurfer.current.loadBlob(audioData); //must be a Blob
  }

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

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