From 87e8d298fedbaefeb86f1219db34491eb6db5b4f Mon Sep 17 00:00:00 2001 From: Antares Date: Wed, 4 Mar 2020 12:25:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins_new/read/plugin.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins_new/read/plugin.py b/plugins_new/read/plugin.py index a9eae4e..eb011a2 100644 --- a/plugins_new/read/plugin.py +++ b/plugins_new/read/plugin.py @@ -29,10 +29,16 @@ class ReadConfig(ConfigBase): class ReadPlugin(Plugin): async def get_voice(self, text: str, token: str) -> bytes: - async with self.aioclient.post("https://tsn.baidu.com/text2audio", - data=f"tex={urllib.parse.quote(urllib.parse.quote(text))}\ -&ctp=1&tok={token}&cuid=qwqqwqqwqqwq&spd={self.config.SPEED}\ -&per=4&vol={self.config.VOLUME}&lan=zh") as resp: + async with self.aioclient.post("https://tsn.baidu.com/text2audio",data={ + "tex":urllib.parse.quote(urllib.parse.quote(text)), + "tok":token, + "cuid":"qwqqwqqwq", + "ctp": 1, + "spd":self.config.SPEED, + "per":4, + "vol":self.config.VOLUME, + "lan":"zh" + }) as resp: resp: aiohttp.ClientResponse result = await resp.read() return result @@ -45,17 +51,18 @@ class ReadPlugin(Plugin): }) as resp: resp: aiohttp.ClientResponse result = await resp.json() - if "access_token" in result: - return result['access_token'] - else: - return "xxx" + return result['access_token'] async def command_read(self, plugin, args: List[str], raw_string: str, context, evt: MessageEvent): text = " ".join(args) if len(text) > self.config.MAX_STRING_LENGTH: await self.bot.client_async.send(context, "字符串过长") else: - token = await self.get_token() + try: + token = await self.get_token() + except Exception: + self.logger.error("Read: 获取token失败,请检查API_KEY和SECRET_KEY") + return data = await self.get_voice(text, token) try: info = json.loads(data.decode()) -- Gitee