NodeJS:通过 fs.writeFile 和 Blob 创建的每个音频文件都长度过大

发布于 2025-01-12 09:44:21 字数 722 浏览 6 评论 0原文

我正在创建一个应用程序,需要获取用户的语音并将其转换为文本,但音频文件创建后的长度似乎有问题。

这里是我收集音频并将数据转换为 Blob 的方式。我只是使用 getUserMedia 方法来录制音频并在停止时将其转换为 Blob。

这是我将 Blob 对象传递给的函数的开头。我将 Blob 转换为缓冲区,并将该缓冲区写入项目根目录中的文件中。但是一旦文件写完,我去听它,无论原始音频有多长,音频的长度都是435:13:24。但即使长度那么长,该文件听起来也完全像它应该的那样,并且在正确的时间结束。

Img 这是查看文件时的样子的图片。

尽管这似乎不是什么大问题,因为收听文件提供了正确的音频,但我将文件传递给将其转换为文本的 API,并且它几乎总是给出错误的翻译或有关包含以下内容的文件的错误:没有什么。我尝试了不同的方法将 Blob 数据写入文件,并尝试切断多余长度的音频,但没有任何效果。

这是我关于堆栈溢出的第一篇文章,因为我没有办法解决这个问题,所以如果问题有点模糊或者我以某种方式错误地格式化了它,我很抱歉。

I'm creating an app which needs to take the user's voice and convert it to text, but the audio file seems to have something wrong with the length after it's creation.

Here is how I'm gathering the audio and converting the data to a Blob. I'm just using the getUserMedia method to record the audio and convert it to a Blob when its stopped.

This is the beginning of the function I pass the Blob object to. I convert the Blob to a buffer and write that buffer to a file in the root directory of my project. But once the file has been written and I go to listen to it, the length of the audio is 435:13:24 no matter how long the original audio was. But even though the length is that long, the file sounds exactly like it should and ends at the correct time.

Img Heres a picture of what the file looks like when viewed.

Although this may not seem like a big deal since listening to the file provides the correct audio, I'm passing the file to an API that converts it to text, and it almost always gives either the wrong translation or an error about the file containing nothing. I've tried different ways of writing the Blob data to the file, and tried cutting off the excess length audio, but nothing has worked.

This is my first post on stack overflow since I ran out of options to fix this, so I'm sorry if the question is kind of vague or I formatted it incorrectly in some way.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文