Possible to send audio files through websocket? [closed]

假装没事ソ 提交于 2021-01-29 05:53:34

问题


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)

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.


回答1:


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

  • encode your audio into MP3 or OGG or whatever your target browser(s) support
  • send it over the web socket to the client
  • receive the data into something blob-like

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.


来源:https://stackoverflow.com/questions/55706926/possible-to-send-audio-files-through-websocket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!