可以通过websocket发送音频文件吗? [英] Possible to send audio files through websocket?

查看:62
本文介绍了可以通过websocket发送音频文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 Web 应用程序,该应用程序根据用户的输入生成一个新的音频文件.wav 文件是在我们的 python 后端生成的,现在我希望能够在前端向用户播放它.我怎样才能用 websockets 做到这一点?(我已经在应用程序中使用了)

I am building a web application that generates a new audio file depending on the input from the user. The wav file is generated in our python backend and now I want to be able to play it to the user on the frontend. How can I do this with websockets? (which I'm already using in the application)

我在 stackoverflow 上查看了其他几篇文章,但没有人回答我的问题,因为我没有使用 Angular、Node 或 React.前端只用 Javascript,后端用 python.

I have looked at several other posts here att stackoverflow but none answers my question as I'm not using Angular, Node or React. Just Javascript for frontend and python for the backend.

推荐答案

我不明白你为什么不能这样做.

I don't see why you couldn't do this.

  • 将您的音频编码为 MP3 或 OGG 或您的目标浏览器支持的任何内容
  • 通过网络套接字将其发送到客户端
  • 将数据接收到blob之类的

然后,取决于你想怎么玩,

Then, depending on how you want to play things,

  • generate an object URL out of the data and pass that in as the src for an <audio> tag, or
  • use the Web Audio API and decodeAudioData to get a buffer source you can play.

这篇关于可以通过websocket发送音频文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆