add encryption in todo
This commit is contained in:
+20
-13
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: res.py
|
||||
# Date: Fri Mar 27 23:42:16 2015 +0800
|
||||
# Date: Sun Apr 19 17:11:07 2015 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import glob
|
||||
@@ -33,20 +33,24 @@ JPEG_QUALITY = 50
|
||||
|
||||
def do_get_voice_mp3(amr_fpath):
|
||||
""" return base64 string, and voice duration"""
|
||||
if not amr_fpath: return "", 0
|
||||
mp3_file = os.path.join('/tmp',
|
||||
os.path.basename(amr_fpath)[:-4] + '.mp3')
|
||||
try:
|
||||
if not amr_fpath: return "", 0
|
||||
mp3_file = os.path.join('/tmp',
|
||||
os.path.basename(amr_fpath)[:-4] + '.mp3')
|
||||
|
||||
infile = pysox.CSoxStream(amr_fpath)
|
||||
outfile = pysox.CSoxStream(mp3_file, 'w', infile.get_signal())
|
||||
chain = pysox.CEffectsChain(infile, outfile)
|
||||
chain.flow_effects()
|
||||
outfile.close()
|
||||
infile = pysox.CSoxStream(amr_fpath)
|
||||
outfile = pysox.CSoxStream(mp3_file, 'w', infile.get_signal())
|
||||
chain = pysox.CEffectsChain(infile, outfile)
|
||||
chain.flow_effects()
|
||||
outfile.close()
|
||||
|
||||
signal = infile.get_signal().get_signalinfo()
|
||||
duration = signal['length'] * 1.0 / signal['rate']
|
||||
mp3_string = get_file_b64(mp3_file)
|
||||
os.unlink(mp3_file)
|
||||
signal = infile.get_signal().get_signalinfo()
|
||||
duration = signal['length'] * 1.0 / signal['rate']
|
||||
mp3_string = get_file_b64(mp3_file)
|
||||
os.unlink(mp3_file)
|
||||
except:
|
||||
logger.warn("Failed to prepare voice file. Wechat changed their protocol!")
|
||||
return 'fail', 0.1
|
||||
return mp3_string, duration
|
||||
|
||||
class Resource(object):
|
||||
@@ -90,6 +94,9 @@ class Resource(object):
|
||||
pool = Pool(3)
|
||||
self.voice_cache = [pool.apply_async(do_get_voice_mp3,
|
||||
(self.get_voice_filename(k),)) for k in voice_paths]
|
||||
# single-threaded version, for debug
|
||||
#self.voice_cache = map(do_get_voice_mp3,
|
||||
#(self.get_voice_filename(k) for k in voice_paths))
|
||||
|
||||
def get_avatar(self, username):
|
||||
""" return base64 string"""
|
||||
|
||||
Reference in New Issue
Block a user