概述
我正在使用cherrypy将WAV文件从浏览器保存到本地磁盘.传入:
{'audio_file': [, ], 'user_data': u'{"id":"1255733204",'audio_length': [u'10.03102', u'22.012517', u'22.012517']}
我收到此错误:
try:
f = open('/audiostory/'+filename,'wb')
logging.debug( '[SAVEAUDIO] tried to write all of audio_file input at once' )
f.write(kw.get('audio_file'))
f.close()
logging.debug( ('saved media file %s to /audiostory/' % f.name) )
except Exception as e:
logging.debug( ('saved media NOT saved %s because %s' % (f.name,str(e))) )
"Must be convertible to a buffer, not Part."
那么我该如何处理这类数据,即将其转换为’.Part’但它应该是原始的WAV数据?我是否缺少标题或其他内容?
更新
杰森(Jason)-您会看到我故意没有发送任何标头或其他信息,因为我想看看小巧的东西会带来原始效果.这是cherrypy site.py文件:
@cherrypy.expose
def saveaudio(self, *args, **kw):
import audiosave
return audiosave.raw_audio(kw.get('audio_file'))
以及audiosave中的功能:
def raw_audio(raw):
""" is fed a raw stream of data (I think) and saves it to disk, with logging. """
import json
import logging
LOG_FILENAME = 'error.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logging.debug( '[SAVEAUDIO(raw)]'+str(raw) )
filename = assign_filename()
try:
#SAVE FILE TO DISK /s/audiostory/
f = open('/home/djotjog/webapps/s/audiostory/'+filename,'wb')
logging.debug( '[SAVEAUDIO] tried to write all of audio_file input at once' )
f.write(raw)
f.close()
logging.debug( ('media SAVED %s' % f.name) )
except Exception as e:
logging.debug( ('media NOT saved %s because %s' % (f.name,str(e))) )
return json.dumps({"result":"414","message":"ERROR: Error saving Media file "+f.name})
return raw
我也尝试了f.write(raw.file.read()),但发生相同的错误.
最后
以上就是留胡子鞋子为你收集整理的python把wav本地转文字_python-将WAV字节从POST数据保存到磁盘(cherryp...的全部内容,希望文章能够帮你解决python把wav本地转文字_python-将WAV字节从POST数据保存到磁盘(cherryp...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复