From 7fcc92be5f106475c2a2ef32a8ade0aa03dc9044 Mon Sep 17 00:00:00 2001 From: ZhehaoMi <1125263974@qq.com> Date: Wed, 20 Feb 2019 01:50:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96read=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/read/read.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/plugins/read/read.py b/plugins/read/read.py index 5355e53..3c62c4c 100644 --- a/plugins/read/read.py +++ b/plugins/read/read.py @@ -34,19 +34,13 @@ def read(bot, context, args): 'per': 4, 'spd': config.SPEED }) - - tmpdir = tempfile.mkdtemp() - audiopath = os.path.join(tmpdir, "audio.mp3") - + if not isinstance(voice, dict): - with open(audiopath, "wb") as file: - file.write(voice) + result = "" + with open(audiopath, "rb") as file: + result = base64.encodebytes(file.read()).decode().replace("\n", "") + bot.send(context, "[CQ:record,file=base64://{}]".format(result)) else: bot.send(context, "转换语音失败,请检查是否含有非法字符") - return - - result = "" - with open(audiopath, "rb") as file: - result = base64.encodebytes(file.read()).decode().replace("\n", "") - bot.send(context, "[CQ:record,file=base64://{}]".format(result)) + threading.Thread(target=handle).start() -- Gitee From 393ba66f0edc6f1113244fa0a6db504c286c107f Mon Sep 17 00:00:00 2001 From: ZhehaoMi <1125263974@qq.com> Date: Wed, 20 Feb 2019 02:05:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96read=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/read/read.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/read/read.py b/plugins/read/read.py index 3c62c4c..d4ca1cf 100644 --- a/plugins/read/read.py +++ b/plugins/read/read.py @@ -36,10 +36,8 @@ def read(bot, context, args): }) if not isinstance(voice, dict): - result = "" - with open(audiopath, "rb") as file: - result = base64.encodebytes(file.read()).decode().replace("\n", "") - bot.send(context, "[CQ:record,file=base64://{}]".format(result)) + result = str(base64.encodebytes(voice).decode().replace("\n", "")) + bot.send(context, "[CQ:record,file=base64://{}]".format(result)) else: bot.send(context, "转换语音失败,请检查是否含有非法字符") -- Gitee