Skip to main content

基于 Nonebot2 的语音功能适配插件,包括语音事件响应器,语音识别、语音合成等功能

Project description

NoneBotPluginLogo

NoneBotPluginText

Nonebot-Plugin-Record

✨ 基于 NoneBot2 的语音功能适配插件 ✨

license Python NoneBot pypi

功能

  • 语音事件响应器(仅限私聊)
  • 语音识别(仅限私聊,支持百度智能云、腾讯云接口)
  • 语音合成(利用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次免费调用量(推荐)

获取密钥

如何使用?

语音事件响应器的使用

语音事件响应器:on_record()

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

选填参数:

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

代码示例:

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

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

获取语音中的文本

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

必填参数:

bot: Bot 对象
event: Event 对象

代码示例:

# 导入依赖包
from nonebot import require
require('nonebot_plugin_record')
from nonebot_plugin_record import get_text

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

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

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

必填参数:

patter: 要进行转换的字符串

代码示例:

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

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

插件示例

私聊语音聊天插件:

from nonebot.adapters.onebot.v11 import (
    Event,
    Bot
)
from nonebot import require
require('nonebot_plugin_record')
from src.plugins.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

更新日志

2021/1/15 [v1.0.1]

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

2023/1/15 [v1.0.0]

  • 发布插件

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_record-1.0.1.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

nonebot_plugin_record-1.0.1-py3-none-any.whl (7.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page