如何流式传输 WAV 文件?

发布于 2024-08-27 23:01:06 字数 325 浏览 9 评论 0原文

我正在编写一个应用程序,在其中录制音频并通过网络上传音频文件。为了加快上传速度,我想在完成录制之前开始上传。

我正在创建的文件是 WAV 文件。我的计划是使用多个数据块。因此,我使用的不是普通编码(RIFF、fmt、data)(RIFF、fmt、data、data、...、data)。第一个问题是 RIFF 标头需要整个文件的总长度,但这在流式传输音频时当然是未知的(我现在使用任意数字)。另一个问题是我不确定它是否有效,因为 Audacity 无法识别该文件,并且 Windows Media Player 打开该文件但只播放很小的一部分。我一直在阅读 WAV 规范,但没有找到答案。

有什么建议吗?

I'm writing an app where I record audio and upload the audio file over the web. In order to speed up the upload I want to start uploading before I've finished recording.

The file I'm creating is a WAV file. My plan was to use multiple data chunks. So instead of the normal encoding (RIFF, fmt , data) I’m using (RIFF, fmt , data, data, ..., data). The first issue is that the RIFF header wants the total length of the whole file, but that is of course not known when streaming the audio (I’m now using an arbitrary number). The other problem is that I'm not sure if it's valid since Audacity doesn't recognise the file, and Windows Media Player opens the file but plays only a very small part. I've been reading WAV specs but haven’t found an answer.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青萝楚歌 2024-09-03 23:01:06

我成功地通过仅使用一个数据块并将 ChunkSize 设置为 0xFFFFFFFF 并将 Subchunk2Size 设置为 0xFFFFFFFF 来流式传输 wav。生成的文件并不完全符合规格,但当通过 标签嵌入时,Chrome 可以毫无问题地实时播放它。下载的文件也可以播放。

WAV 格式

I've managed to stream a wav by using only one data chunk and setting ChunkSize to 0xFFFFFFFF and Subchunk2Size to 0xFFFFFFFF as well. The resulting file is not completely up to the specs but when embedded via <audio> tag, Chrome plays it in real-time without a problem. Also the downloaded file is playable.

WAV format

冷月断魂刀 2024-09-03 23:01:06

您只需使用支持附加的容器格式,而无需编辑标头。

我建议使用原始 PCM 样本。它们可以随意转换为其他任何东西。

Audacity 将从文件导入原始字节 ->导入->原始数据菜单。

另一种选择可能是无损音频编解码器,例如可流式容器格式内的 FLAC。 (由捷克网络广播电台完成)

我请注意,VLC 可以从声卡压缩和流式传输 FLAC-in-OGG。从这里开始,在服务器端存储或解压缩流应该是一个简单的步骤。

You will just have to use a container format that supports appending without editing the header.

I suggest Raw PCM samples. They can be converted to anything else at will.

Audacity will import raw bytes from the File -> Import -> Raw Data menu.

Another option might be a lossless audio codec such as FLAC inside of a streamable container format. (As done by a Czech web radio station)

I notice VLC can compress and stream FLAC-in-OGG from the soundcard. Should be a simple step from there to store or uncompress the stream on the server end.

谁的新欢旧爱 2024-09-03 23:01:06

你要上传到哪里?你自己的网站?听起来您需要一些服务器端代码来获取原始样本上传并将它们组装成服务器上的有效 WAV 文件(正确的文件长度字段,一个数据块)。

但如果您确实想加快上传速度,我认为您实际上想要上传 MP3 编码的帧并让服务器将它们组装成 MP3 文件。恐怕哪个更复杂。

Where are you uploading to? Your own site? Sounds like you need some server-side code to take your raw sample uploads and assemble them into a valid WAV file (correct file-length field, one data chunk) on the server.

But if you're really trying to speed up the upload, I'd think you actually want to upload MP3-encoded frames and have the server assemble those into an MP3 file. Which is more complicated, I'm afraid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文