How to play a audio file through http response in django(python)

[亡魂溺海] 提交于 2019-12-04 20:55:56
Sharadhi Ballal

I found the answer.....

 def playAudioFile(request):
    fname="C:\\test\\audio\\audio.mp3"
    f = open(fname,"rb") 
    response = HttpResponse()
    response.write(f.read())
    response['Content-Type'] ='audio/mp3'
    response['Content-Length'] =os.path.getsize(fname )
    return response

well if you have the file you can do this

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