我想在网站上播放一个audion,并在Django模板中播放音频 我用这段代码来获取音频
import urllib
import urllib2
def get_sound(goal_word):
headers = {"User-Agent":"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"}
url = "http://dict.youdao.com/dictvoice"
word = goal_word
cuntry = "2"
params = {"audio":word, "type":cuntry}
data = urllib.urlencode(params)
request = urllib2.Request(url, data, headers)
response = urllib2.urlopen(request)
fs = open("temp.wav", 'wb')
fs.write(response.read())
fs.close()
我发现HTML5可以播放音频
<audio></audio>
所以我将它添加到我的模板
<ul id="nav-one" class="nav">
<audio id="beep-one" controls="controls" preload="auto">
<source src="{% static 'audio/beep.wav' %}"></source>
<source src="{% static 'audio/beep.ogg' %}"></source>
</audio>
</ul>
但它没有播放,也没有播放错误信息
这是我的setting.py
STATIC_PATH = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (STATIC_PATH,)
我的文件树:
myproject
----myproject
--------__init__.py
--------settings.py
--------urls.py
--------wsgi.py
----static
---------audio
-------------beep.wav
现在应该做什么?