MediaRecorder 中录制块的回调

发布于 2024-10-07 16:34:48 字数 228 浏览 0 评论 0原文

我正在尝试使用 Media Recorder 类录制麦克风的声音。在提到的类中,我们刚刚有 setOutputFile 方法来设置输出文件,但我需要获取某些录制语音的缓冲区,我的意思是我需要类似 CallBack 方法的东西,它返回当时录制的字节块,我是将上述字节发送到另一个设备...

实际上,我想通过套接字流式传输录制的语音并将其发送到另一个设备,同时不保存录制的语音,然后读取文件并发送它,因为它会导致意外的延迟。 ..

I am trying to record a voice from Mic using Media Recorder class. in the mentioned class we have just setOutputFile method to set the output file, but I need to get a buffer of some certain recorded voice, I mean i need something like a CallBack method that return a block of recorded byte at that time and i am going to send the mentioned bytes to another device...

Actually I want to stream and send the recorded voice through socket to another device simultaneously not saving the recorded voice and then read the file and send it, due to it results an unexpected delay...

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

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

发布评论

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

评论(1

沩ん囻菔务 2024-10-14 16:34:48

Alireza,

这可以很容易地完成。您所要做的就是设置一个套接字,从该套接字创建一个 ParcelFileDescriptor,然后在 setOutputFile 中设置此文件描述符。这将设置流部分,但随后您将遇到文件的一些格式问题。这是因为 MediaRecorder 保留了文件的标头空间,但仅在流完成后才写入。为了在服务器端拥有一个功能文件,您必须解析标头,并将其写入文件(或缓冲区)的开头。

祝你好运,
B-辐射

Alireza,

This can be done pretty easily. All you have to do is set up a socket, from that socket you create a ParcelFileDescriptor, then set this file descriptor in setOutputFile. This will set up the streaming part, but then you will have some formatting issues with the file afterwards. This is because MediaRecorder reserves the header space of the file, but only writes it after the stream has finished. In order to have a functional file on the server-side, you will have to parse the header, and write it to the beginning of the file (or buffer).

Good luck,
B-Rad

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