nonebot-plugin-record


Namenonebot-plugin-record JSON
Version 1.0.4 PyPI version JSON
download
home_pagehttps://github.com/itsevin/nonebot_plugin_record
Summary基于 Nonebot2 的语音功能适配插件,包括语音事件响应器,语音识别、语音合成等功能
upload_time2023-05-13 08:14:00
maintainer
docs_urlNone
authorITSevin
requires_python>=3.8,<4.0
licenseMIT
keywords nonebot nonebot2 nonebot_plugin_record
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
  <a href="https://v2.nonebot.dev/store"><img src="https://s2.loli.net/2022/06/16/opBDE8Swad5rU3n.png" width="180" height="180" alt="NoneBotPluginLogo"></a>
  <br>
  <p><img src="https://s2.loli.net/2022/06/16/xsVUGRrkbn1ljTD.png" width="240" alt="NoneBotPluginText"></p>
</div>

<div align="center">

# Nonebot-Plugin-Record

_✨ 基于 [NoneBot2](https://v2.nonebot.dev/) 的语音功能适配插件 ✨_

<p align="center">
  <img src="https://img.shields.io/github/license/itsevin/nonebot_plugin_record" alt="license">
  <img src="https://img.shields.io/badge/python-3.8+-blue.svg" alt="Python">
  <img src="https://img.shields.io/badge/nonebot-2.0.0b4+-red.svg" alt="NoneBot">
  <a href="https://pypi.org/project/nonebot-plugin-record">
    <img src="https://badgen.net/pypi/v/nonebot-plugin-record" alt="pypi">
  </a>
</p>

</div>

## 功能

- 语音事件响应器(仅限私聊)
- 语音识别(仅限私聊,支持百度智能云、腾讯云接口)
- 语音合成(利用TX的tts接口)

## 安装

- 使用 nb-cli

```
nb plugin install nonebot-plugin-record
```

- 使用 pip

```
pip install nonebot_plugin_record
```

## 配置项

```
asr_api_provider="" #必填,API提供商,填写“baidu”或“tencent”
asr_api_key="" #必填,百度智能云的API_KRY或腾讯云的SECRET_ID
asr_secret_key="" #必填,百度智能云的SECRET_KRY或腾讯云的SECRET_KEY
nonebot_plugin_gocqhttp=False #选填,是否使用nonebot2插件版本的go-cqhttp,默认为False
```

## API选择与配置

### 选什么API?

- 百度智能云-短语音识别标准版:5并发,15万次免费调用量,期限180天
- 腾讯云-一句话识别:每月5000次免费调用量(推荐)

### 获取密钥

- 百度智能云:https://ai.baidu.com/tech/speech
- 腾讯云:https://cloud.tencent.com/document/product/1093

## 如何使用?

### 语音事件响应器的使用

语音事件响应器:```on_record()```

说明:语音事件响应器继承自```on_message```,在其上增加了自定义的相应事件响应规则

选填参数:

```
rule: 事件响应规则
permission: 事件响应权限
handlers: 事件处理函数列表
temp: 是否为临时事件响应器(仅执行一次)
expire_time: 事件响应器最终有效时间点,过时即被删除
priority: 事件响应器优先级
block: 是否阻止事件向更低优先级传递
state: 默认 state
```

代码示例:

```python
# 导入依赖包
from nonebot import require
require('nonebot_plugin_record')
from nonebot_plugin_record import on_record

# 注册语音事件响应器
matcher = on_record()
```

### 获取语音中的文本

获取文本的异步函数:```get_text```()

必填参数:

```
bot: Bot 对象
event: Event 对象
```

代码示例:

```python
# 导入依赖包
from nonebot import require
require('nonebot_plugin_record')
from nonebot_plugin_record import get_text
from nonebot.adapters.onebot.v11 import Event, Bot

# 事件处理中获取文本
text = await get_text(bot=bot, event=event)
```

> 当函数出错时会返回None,具体报错信息请前往Nonebot2进程日志查看

### 获取文本转换的语音的```Message```对象

获取文本转换的语音的Message对象的异步函数:```record_tts```()

必填参数:
```
patter: 要进行转换的字符串
```

代码示例:

```python
# 导入依赖包
from nonebot import require
require('nonebot_plugin_record')
from nonebot_plugin_record import record_tts

# 事件处理中获取文本转换的语音的Message对象
record_tts(pattern=pattern)
```

### 插件示例

私聊语音聊天插件:

```python
from nonebot.adapters.onebot.v11 import (
    Event,
    Bot
)
from nonebot import require
require('nonebot_plugin_record')
from nonebot_plugin_record import (
    on_record,
    get_text,
    record_tts
)

import httpx
import json


chat = on_record()


@chat.handle()
async def main(bot: Bot, event: Event):
    text = await get_text(bot, event)
    msg = await get_data(text)
    await chat.finish(record_tts(msg))


async def get_data(msg):
    url = f'http://api.qingyunke.com/api.php?key=free&appid=0&msg={msg}'
    async with httpx.AsyncClient() as client:
        resp = await client.get(url)
        get_dic = json.loads(resp.text)
    data = get_dic['content']
    return data

```

## 有问题怎么办?

1. 确认是不是你自己的插件的问题
2. 确认是否正确按照本插件使用说明使用
3. 排查日志,通过日志内容尝试找出问题并自行解决
4. 在配置文件中配置```LOG_LEVEL=DEBUG```,然后在日志中查看debug日志,并同时根据本插件源码尝试找出问题并自行解决(确认是本插件的问题可以提issue或者pr)
5. 问题仍未解决可以提issue,要求提供详细问题描述和较为完整的debug级别的相关日志

## 更新日志

### 2023/5/13 \[v1.0.4]

- 重构代码,舍弃CQ码过时写法
- 增加dubug和info级别的日志输出

### 2023/1/27 \[v1.0.3]

- 修复错误

### 2023/1/15 \[v1.0.2]

- 修复错误

### 2023/1/15 \[v1.0.1]

- 适配Nonebot2商店插件自动检测,删除配置文件报错提醒

### 2023/1/15 \[v1.0.0]

- 发布插件

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/itsevin/nonebot_plugin_record",
    "name": "nonebot-plugin-record",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "nonebot,nonebot2,nonebot_plugin_record",
    "author": "ITSevin",
    "author_email": "itsevin@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/ce/dc/44a45f8a945cbcf08b10268abb021fc7bd8019815ed2afe994c5442c7b83/nonebot_plugin_record-1.0.4.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n  <a href=\"https://v2.nonebot.dev/store\"><img src=\"https://s2.loli.net/2022/06/16/opBDE8Swad5rU3n.png\" width=\"180\" height=\"180\" alt=\"NoneBotPluginLogo\"></a>\n  <br>\n  <p><img src=\"https://s2.loli.net/2022/06/16/xsVUGRrkbn1ljTD.png\" width=\"240\" alt=\"NoneBotPluginText\"></p>\n</div>\n\n<div align=\"center\">\n\n# Nonebot-Plugin-Record\n\n_\u2728 \u57fa\u4e8e [NoneBot2](https://v2.nonebot.dev/) \u7684\u8bed\u97f3\u529f\u80fd\u9002\u914d\u63d2\u4ef6 \u2728_\n\n<p align=\"center\">\n  <img src=\"https://img.shields.io/github/license/itsevin/nonebot_plugin_record\" alt=\"license\">\n  <img src=\"https://img.shields.io/badge/python-3.8+-blue.svg\" alt=\"Python\">\n  <img src=\"https://img.shields.io/badge/nonebot-2.0.0b4+-red.svg\" alt=\"NoneBot\">\n  <a href=\"https://pypi.org/project/nonebot-plugin-record\">\n    <img src=\"https://badgen.net/pypi/v/nonebot-plugin-record\" alt=\"pypi\">\n  </a>\n</p>\n\n</div>\n\n## \u529f\u80fd\n\n- \u8bed\u97f3\u4e8b\u4ef6\u54cd\u5e94\u5668\uff08\u4ec5\u9650\u79c1\u804a\uff09\n- \u8bed\u97f3\u8bc6\u522b\uff08\u4ec5\u9650\u79c1\u804a\uff0c\u652f\u6301\u767e\u5ea6\u667a\u80fd\u4e91\u3001\u817e\u8baf\u4e91\u63a5\u53e3\uff09\n- \u8bed\u97f3\u5408\u6210\uff08\u5229\u7528TX\u7684tts\u63a5\u53e3\uff09\n\n## \u5b89\u88c5\n\n- \u4f7f\u7528 nb-cli\n\n```\nnb plugin install nonebot-plugin-record\n```\n\n- \u4f7f\u7528 pip\n\n```\npip install nonebot_plugin_record\n```\n\n## \u914d\u7f6e\u9879\n\n```\nasr_api_provider=\"\" #\u5fc5\u586b\uff0cAPI\u63d0\u4f9b\u5546\uff0c\u586b\u5199\u201cbaidu\u201d\u6216\u201ctencent\u201d\nasr_api_key=\"\" #\u5fc5\u586b\uff0c\u767e\u5ea6\u667a\u80fd\u4e91\u7684API_KRY\u6216\u817e\u8baf\u4e91\u7684SECRET_ID\nasr_secret_key=\"\" #\u5fc5\u586b\uff0c\u767e\u5ea6\u667a\u80fd\u4e91\u7684SECRET_KRY\u6216\u817e\u8baf\u4e91\u7684SECRET_KEY\nnonebot_plugin_gocqhttp=False #\u9009\u586b\uff0c\u662f\u5426\u4f7f\u7528nonebot2\u63d2\u4ef6\u7248\u672c\u7684go-cqhttp\uff0c\u9ed8\u8ba4\u4e3aFalse\n```\n\n## API\u9009\u62e9\u4e0e\u914d\u7f6e\n\n### \u9009\u4ec0\u4e48API?\n\n- \u767e\u5ea6\u667a\u80fd\u4e91-\u77ed\u8bed\u97f3\u8bc6\u522b\u6807\u51c6\u7248\uff1a5\u5e76\u53d1\uff0c15\u4e07\u6b21\u514d\u8d39\u8c03\u7528\u91cf\uff0c\u671f\u9650180\u5929\n- \u817e\u8baf\u4e91-\u4e00\u53e5\u8bdd\u8bc6\u522b\uff1a\u6bcf\u67085000\u6b21\u514d\u8d39\u8c03\u7528\u91cf\uff08\u63a8\u8350\uff09\n\n### \u83b7\u53d6\u5bc6\u94a5\n\n- \u767e\u5ea6\u667a\u80fd\u4e91\uff1ahttps://ai.baidu.com/tech/speech\n- \u817e\u8baf\u4e91\uff1ahttps://cloud.tencent.com/document/product/1093\n\n## \u5982\u4f55\u4f7f\u7528\uff1f\n\n### \u8bed\u97f3\u4e8b\u4ef6\u54cd\u5e94\u5668\u7684\u4f7f\u7528\n\n\u8bed\u97f3\u4e8b\u4ef6\u54cd\u5e94\u5668\uff1a```on_record()```\n\n\u8bf4\u660e\uff1a\u8bed\u97f3\u4e8b\u4ef6\u54cd\u5e94\u5668\u7ee7\u627f\u81ea```on_message```\uff0c\u5728\u5176\u4e0a\u589e\u52a0\u4e86\u81ea\u5b9a\u4e49\u7684\u76f8\u5e94\u4e8b\u4ef6\u54cd\u5e94\u89c4\u5219\n\n\u9009\u586b\u53c2\u6570\uff1a\n\n```\nrule: \u4e8b\u4ef6\u54cd\u5e94\u89c4\u5219\npermission: \u4e8b\u4ef6\u54cd\u5e94\u6743\u9650\nhandlers: \u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u5217\u8868\ntemp: \u662f\u5426\u4e3a\u4e34\u65f6\u4e8b\u4ef6\u54cd\u5e94\u5668\uff08\u4ec5\u6267\u884c\u4e00\u6b21\uff09\nexpire_time: \u4e8b\u4ef6\u54cd\u5e94\u5668\u6700\u7ec8\u6709\u6548\u65f6\u95f4\u70b9\uff0c\u8fc7\u65f6\u5373\u88ab\u5220\u9664\npriority: \u4e8b\u4ef6\u54cd\u5e94\u5668\u4f18\u5148\u7ea7\nblock: \u662f\u5426\u963b\u6b62\u4e8b\u4ef6\u5411\u66f4\u4f4e\u4f18\u5148\u7ea7\u4f20\u9012\nstate: \u9ed8\u8ba4 state\n```\n\n\u4ee3\u7801\u793a\u4f8b\uff1a\n\n```python\n# \u5bfc\u5165\u4f9d\u8d56\u5305\nfrom nonebot import require\nrequire('nonebot_plugin_record')\nfrom nonebot_plugin_record import on_record\n\n# \u6ce8\u518c\u8bed\u97f3\u4e8b\u4ef6\u54cd\u5e94\u5668\nmatcher = on_record()\n```\n\n### \u83b7\u53d6\u8bed\u97f3\u4e2d\u7684\u6587\u672c\n\n\u83b7\u53d6\u6587\u672c\u7684\u5f02\u6b65\u51fd\u6570\uff1a```get_text```()\n\n\u5fc5\u586b\u53c2\u6570\uff1a\n\n```\nbot: Bot \u5bf9\u8c61\nevent: Event \u5bf9\u8c61\n```\n\n\u4ee3\u7801\u793a\u4f8b\uff1a\n\n```python\n# \u5bfc\u5165\u4f9d\u8d56\u5305\nfrom nonebot import require\nrequire('nonebot_plugin_record')\nfrom nonebot_plugin_record import get_text\nfrom nonebot.adapters.onebot.v11 import Event, Bot\n\n# \u4e8b\u4ef6\u5904\u7406\u4e2d\u83b7\u53d6\u6587\u672c\ntext = await get_text(bot=bot, event=event)\n```\n\n> \u5f53\u51fd\u6570\u51fa\u9519\u65f6\u4f1a\u8fd4\u56deNone\uff0c\u5177\u4f53\u62a5\u9519\u4fe1\u606f\u8bf7\u524d\u5f80Nonebot2\u8fdb\u7a0b\u65e5\u5fd7\u67e5\u770b\n\n### \u83b7\u53d6\u6587\u672c\u8f6c\u6362\u7684\u8bed\u97f3\u7684```Message```\u5bf9\u8c61\n\n\u83b7\u53d6\u6587\u672c\u8f6c\u6362\u7684\u8bed\u97f3\u7684Message\u5bf9\u8c61\u7684\u5f02\u6b65\u51fd\u6570\uff1a```record_tts```()\n\n\u5fc5\u586b\u53c2\u6570\uff1a\n```\npatter: \u8981\u8fdb\u884c\u8f6c\u6362\u7684\u5b57\u7b26\u4e32\n```\n\n\u4ee3\u7801\u793a\u4f8b\uff1a\n\n```python\n# \u5bfc\u5165\u4f9d\u8d56\u5305\nfrom nonebot import require\nrequire('nonebot_plugin_record')\nfrom nonebot_plugin_record import record_tts\n\n# \u4e8b\u4ef6\u5904\u7406\u4e2d\u83b7\u53d6\u6587\u672c\u8f6c\u6362\u7684\u8bed\u97f3\u7684Message\u5bf9\u8c61\nrecord_tts(pattern=pattern)\n```\n\n### \u63d2\u4ef6\u793a\u4f8b\n\n\u79c1\u804a\u8bed\u97f3\u804a\u5929\u63d2\u4ef6\uff1a\n\n```python\nfrom nonebot.adapters.onebot.v11 import (\n    Event,\n    Bot\n)\nfrom nonebot import require\nrequire('nonebot_plugin_record')\nfrom nonebot_plugin_record import (\n    on_record,\n    get_text,\n    record_tts\n)\n\nimport httpx\nimport json\n\n\nchat = on_record()\n\n\n@chat.handle()\nasync def main(bot: Bot, event: Event):\n    text = await get_text(bot, event)\n    msg = await get_data(text)\n    await chat.finish(record_tts(msg))\n\n\nasync def get_data(msg):\n    url = f'http://api.qingyunke.com/api.php?key=free&appid=0&msg={msg}'\n    async with httpx.AsyncClient() as client:\n        resp = await client.get(url)\n        get_dic = json.loads(resp.text)\n    data = get_dic['content']\n    return data\n\n```\n\n## \u6709\u95ee\u9898\u600e\u4e48\u529e\uff1f\n\n1. \u786e\u8ba4\u662f\u4e0d\u662f\u4f60\u81ea\u5df1\u7684\u63d2\u4ef6\u7684\u95ee\u9898\n2. \u786e\u8ba4\u662f\u5426\u6b63\u786e\u6309\u7167\u672c\u63d2\u4ef6\u4f7f\u7528\u8bf4\u660e\u4f7f\u7528\n3. \u6392\u67e5\u65e5\u5fd7\uff0c\u901a\u8fc7\u65e5\u5fd7\u5185\u5bb9\u5c1d\u8bd5\u627e\u51fa\u95ee\u9898\u5e76\u81ea\u884c\u89e3\u51b3\n4. \u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u914d\u7f6e```LOG_LEVEL=DEBUG```\uff0c\u7136\u540e\u5728\u65e5\u5fd7\u4e2d\u67e5\u770bdebug\u65e5\u5fd7\uff0c\u5e76\u540c\u65f6\u6839\u636e\u672c\u63d2\u4ef6\u6e90\u7801\u5c1d\u8bd5\u627e\u51fa\u95ee\u9898\u5e76\u81ea\u884c\u89e3\u51b3\uff08\u786e\u8ba4\u662f\u672c\u63d2\u4ef6\u7684\u95ee\u9898\u53ef\u4ee5\u63d0issue\u6216\u8005pr\uff09\n5. \u95ee\u9898\u4ecd\u672a\u89e3\u51b3\u53ef\u4ee5\u63d0issue\uff0c\u8981\u6c42\u63d0\u4f9b\u8be6\u7ec6\u95ee\u9898\u63cf\u8ff0\u548c\u8f83\u4e3a\u5b8c\u6574\u7684debug\u7ea7\u522b\u7684\u76f8\u5173\u65e5\u5fd7\n\n## \u66f4\u65b0\u65e5\u5fd7\n\n### 2023/5/13 \\[v1.0.4]\n\n- \u91cd\u6784\u4ee3\u7801\uff0c\u820d\u5f03CQ\u7801\u8fc7\u65f6\u5199\u6cd5\n- \u589e\u52a0dubug\u548cinfo\u7ea7\u522b\u7684\u65e5\u5fd7\u8f93\u51fa\n\n### 2023/1/27 \\[v1.0.3]\n\n- \u4fee\u590d\u9519\u8bef\n\n### 2023/1/15 \\[v1.0.2]\n\n- \u4fee\u590d\u9519\u8bef\n\n### 2023/1/15 \\[v1.0.1]\n\n- \u9002\u914dNonebot2\u5546\u5e97\u63d2\u4ef6\u81ea\u52a8\u68c0\u6d4b\uff0c\u5220\u9664\u914d\u7f6e\u6587\u4ef6\u62a5\u9519\u63d0\u9192\n\n### 2023/1/15 \\[v1.0.0]\n\n- \u53d1\u5e03\u63d2\u4ef6\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\u57fa\u4e8e Nonebot2 \u7684\u8bed\u97f3\u529f\u80fd\u9002\u914d\u63d2\u4ef6\uff0c\u5305\u62ec\u8bed\u97f3\u4e8b\u4ef6\u54cd\u5e94\u5668\uff0c\u8bed\u97f3\u8bc6\u522b\u3001\u8bed\u97f3\u5408\u6210\u7b49\u529f\u80fd",
    "version": "1.0.4",
    "project_urls": {
        "Documentation": "https://github.com/itsevin/nonebot_plugin_record#readme",
        "Homepage": "https://github.com/itsevin/nonebot_plugin_record",
        "Repository": "https://github.com/itsevin/nonebot_plugin_record"
    },
    "split_keywords": [
        "nonebot",
        "nonebot2",
        "nonebot_plugin_record"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "065ef9f062e9c9145424bc4afe8cc032c0c30c120f40d56f99c715fcdd5f4312",
                "md5": "ddb2f4713b947521cc66679aefcae5f5",
                "sha256": "08d3510db7127be7c4a7177ae1f59f66d55b022c633ee0e36423697e9cc53d46"
            },
            "downloads": -1,
            "filename": "nonebot_plugin_record-1.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ddb2f4713b947521cc66679aefcae5f5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 8885,
            "upload_time": "2023-05-13T08:13:57",
            "upload_time_iso_8601": "2023-05-13T08:13:57.758101Z",
            "url": "https://files.pythonhosted.org/packages/06/5e/f9f062e9c9145424bc4afe8cc032c0c30c120f40d56f99c715fcdd5f4312/nonebot_plugin_record-1.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cedc44a45f8a945cbcf08b10268abb021fc7bd8019815ed2afe994c5442c7b83",
                "md5": "8f233943f4ec1da38985e3a3572e29ab",
                "sha256": "682711d9217983617f60573de07080243354e1b1c8107cf65a4d5e09503b452a"
            },
            "downloads": -1,
            "filename": "nonebot_plugin_record-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "8f233943f4ec1da38985e3a3572e29ab",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 8265,
            "upload_time": "2023-05-13T08:14:00",
            "upload_time_iso_8601": "2023-05-13T08:14:00.995985Z",
            "url": "https://files.pythonhosted.org/packages/ce/dc/44a45f8a945cbcf08b10268abb021fc7bd8019815ed2afe994c5442c7b83/nonebot_plugin_record-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-13 08:14:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "itsevin",
    "github_project": "nonebot_plugin_record",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "nonebot-plugin-record"
}
        
Elapsed time: 0.06393s