From 618e12ec005440cfa81b48bf696f0616a555de26 Mon Sep 17 00:00:00 2001 From: ppwwyyxx Date: Sun, 23 Nov 2014 18:04:22 +0800 Subject: [PATCH] voice works! --- README.md | 2 ++ lib/render.py | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c5a6cec..3ff1b21 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ #### Install Dependencies: + numpy + PIL ++ audioread ++ sox #### Get Necessary Data: + Get /data/data/com.tencent.mm/MicroMsg/long-long-name/EnMicroMsg.db from rooted phone: diff --git a/lib/render.py b/lib/render.py index 8813b9e..8daf26a 100755 --- a/lib/render.py +++ b/lib/render.py @@ -1,11 +1,12 @@ #!/usr/bin/env python2 # -*- coding: UTF-8 -*- # File: render.py -# Date: Sun Nov 23 17:52:08 2014 +0800 +# Date: Sun Nov 23 18:01:55 2014 +0800 # Author: Yuxin Wu import os import base64 +import audioread LIB_PATH = os.path.dirname(os.path.abspath(__file__)) CSS_FILE = os.path.join(LIB_PATH, 'static/wx.css') HTML_FILE = os.path.join(LIB_PATH, 'static/template.html') @@ -46,8 +47,9 @@ class HTMLRender(object): mp3_file = os.path.join('/tmp', os.path.basename(amr_fpath)[:-4] + '.mp3') os.system('sox {} {}'.format(amr_fpath, mp3_file)) mp3_string = open(mp3_file, 'rb').read() + duration = audioread.audio_open(mp3_file).duration os.unlink(mp3_file) - return base64.b64encode(mp3_string) + return base64.b64encode(mp3_string), duration def render_msg(self, msg): """ render a message, return the block""" @@ -55,9 +57,9 @@ class HTMLRender(object): try: template = ensure_unicode(TEMPLATES[msg.type]) if msg.type == TYPE_SPEAK: - audio_str = self.get_voice_mp3(msg.imgPath) + audio_str, duration = self.get_voice_mp3(msg.imgPath) return template.format(sender_label='you' if not msg.isSend else 'me', - voice_duration=10, + voice_duration=duration, voice_str=audio_str) else: raise