Skip to content

Commit

Permalink
Merge pull request #91 from Ikaros-521/owner
Browse files Browse the repository at this point in the history
新增 答谢功能(入场欢迎、礼物答谢),暂时只支持B站,GUI同步进行配置; 部分live2d文件命名更正
  • Loading branch information
Ikaros-521 authored Jul 10, 2023
2 parents 2643562 + 4b55113 commit aa88232
Show file tree
Hide file tree
Showing 30 changed files with 797 additions and 450 deletions.
2 changes: 1 addition & 1 deletion Live2D/js/model_name.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var model_name = "Hiyori";
var model_name = "haru2";
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -743,17 +743,25 @@ if __name__ == '__main__':

## 待办事项
- [ ] 懒人包优化
- [ ] 接入更多的LLM(科大讯飞、new bing等)
- [ ] 接入更多的TTS方案
- [ ] RVC的接入
- [ ] 快手平台的重新兼容
- [ ] 其他直播平台的适配
- [ ] live2d的嘴型匹配
- [ ] 其他直播平台的适配(tiktok、YouTube、拼多多等)
- [ ] live2d的嘴型、动作匹配
- [ ] 接入更多的2/3D模型软件
- [ ] 屏蔽词升级。如:可以根据屏蔽词库转拼音的二重屏蔽;接入第三方屏蔽词API等
- [ ] 本机语音直接交流模式
- [ ] 本机语音直接交流模式(本地版本whisper,其他方式)
- [ ] 本地的用户拉黑机制
- [ ] 礼物互动机制(跳舞,唱歌)
- [ ] 用户入场、投食感谢(自定义 文案)
- [ ] 弹幕跳过机制
- [ ] 点歌后的弹幕触发问题(如:只取最新的几个)
- [ ] 接入new bing
- [ ] 弹幕丢失bug修复(很可能是线程sleep造成的)
- [ ] wav2lip方案尝试(带货方面)
- [ ] 直播中可以由弹幕进行动态换装
- [ ] TTS合成时,语句切分算法有待优化
- [ ] 压力测试

## 📝 更新日志

Expand Down Expand Up @@ -867,6 +875,7 @@ if __name__ == '__main__':
### 2023-07-10
- GUI可以检索Live2D路径下的模型进行动态修改配置。(需要注意,修改后浏览器缓存问题,请用无痕浏览器打开)
- 追加 Live2D官网所有的免费模型
- 新增 答谢功能(入场欢迎、礼物答谢),暂时只支持B站,GUI同步进行配置。

</details>

Expand Down
393 changes: 218 additions & 175 deletions UI_main.py

Large diffs are not rendered by default.

128 changes: 127 additions & 1 deletion bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def start_server():
room = live.LiveDanmaku(my_handle.get_room_id())

@room.on('DANMU_MSG')
async def on_danmaku(event):
async def _(event):
"""
处理直播间弹幕事件
:param event: 弹幕事件数据
Expand All @@ -33,6 +33,132 @@ async def on_danmaku(event):

my_handle.commit_handle(user_name, content)

@room.on('COMBO_SEND')
async def _(event):
"""
处理直播间礼物连击事件
:param event: 礼物连击事件数据
"""

gift_name = event["data"]["data"]["gift_name"]
user_name = event["data"]["data"]["uname"]
# 礼物数量
combo_num = event["data"]["data"]["combo_num"]
# 总金额
combo_total_coin = event["data"]["data"]["combo_total_coin"]

logging.info(f"用户:{user_name} 赠送 {combo_num}{gift_name},总计 {combo_total_coin}电池")

data = {
"gift_name": gift_name,
"username": user_name,
"num": combo_num,
"unit_price": combo_total_coin / combo_num / 1000,
"total_price": combo_total_coin / 1000
}

my_handle.gift_handle(data)

@room.on('SEND_GIFT')
async def _(event):
"""
处理直播间礼物事件
:param event: 礼物事件数据
"""

# print(event)

gift_name = event["data"]["data"]["giftName"]
user_name = event["data"]["data"]["uname"]
# 礼物数量
num = event["data"]["data"]["num"]
# 总金额
combo_total_coin = event["data"]["data"]["combo_total_coin"]
# 单个礼物金额
discount_price = event["data"]["data"]["discount_price"]

logging.info(f"用户:{user_name} 赠送 {num}{gift_name},单价 {discount_price}电池,总计 {combo_total_coin}电池")

data = {
"gift_name": gift_name,
"username": user_name,
"num": num,
"unit_price": discount_price / 1000,
"total_price": combo_total_coin / 1000
}

my_handle.gift_handle(data)

@room.on('GUARD_BUY')
async def _(event):
"""
处理直播间续费大航海事件
:param event: 续费大航海事件数据
"""

logging.info(event)

@room.on('SUPER_CHAT_MESSAGE')
async def _(event):
"""
处理直播间醒目留言(SC)事件
:param event: 醒目留言(SC)事件数据
"""
message = event["data"]["data"]["message"]
uname = event["data"]["data"]["user_info"]["uname"]
price = event["data"]["data"]["price"]

logging.info(f"用户:{uname} 发送 {price}元 SC:{message}")

data = {
"gift_name": "SC",
"username": uname,
"num": 1,
"unit_price": price,
"total_price": price
}

my_handle.gift_handle(data)

my_handle.commit_handle(uname, message)


@room.on('INTERACT_WORD')
async def _(event):
"""
处理直播间用户进入直播间事件
:param event: 用户进入直播间事件数据
"""
user_name = event["data"]["data"]["uname"]

logging.info(f"用户:{user_name} 进入直播间")

data = {
"username": user_name,
"content": "进入直播间"
}

my_handle.entrance_handle(data)

# @room.on('WELCOME')
# async def _(event):
# """
# 处理直播间老爷进入房间事件
# :param event: 老爷进入房间事件数据
# """

# print(event)

# @room.on('WELCOME_GUARD')
# async def _(event):
# """
# 处理直播间房管进入房间事件
# :param event: 房管进入房间事件数据
# """

# print(event)


try:
# 启动 Bilibili 直播间连接
sync(room.connect())
Expand Down
17 changes: 12 additions & 5 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
"max_len": 80,
"max_char_len": 200
},
"thanks": {
"entrance_enable": true,
"gift_enable": true,
"entrance_copy": "欢迎 {username}",
"gift_copy": "感谢 {username} 送的 {gift_name}",
"lowest_price": 1.0
},
"live2d": {
"enable": true,
"port": 12345
Expand All @@ -37,7 +44,7 @@
"max_new_tokens": 250
},
"chat_with_file": {
"chat_mode": "claude",
"chat_mode": "",
"data_path": "data/伊卡洛斯百度百科.zip",
"separator": "\n",
"chunk_size": 100,
Expand All @@ -53,7 +60,7 @@
"config_path": "D:\\GitHub_pro\\VITS-fast-fine-tuning\\inference\\finetune_speaker.json",
"api_ip_port": "http://127.0.0.1:7860",
"character": "ikaros",
"speed": 1.0
"speed": 1
},
"so_vits_svc": {
"enable": false,
Expand Down Expand Up @@ -112,7 +119,7 @@
"ip": "127.0.0.1",
"port": 7860,
"negative_prompt": "ufsw, longbody, lowres, bad anatomy, bad hands, missing fingers, pubic hair,extra digit, fewer digits, cropped, worst quality, low quality",
"seed": -1.0,
"seed": -1,
"styles": [],
"cfg_scale": 7,
"steps": 30,
Expand All @@ -127,8 +134,8 @@
"file_path": "data/copywriting/",
"audio_path": "out/copywriting/",
"play_list": [],
"audio_interval": 5.0,
"switching_interval": 5.0,
"audio_interval": 5,
"switching_interval": 5,
"random_play": true
},
"header": {
Expand Down
7 changes: 7 additions & 0 deletions config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
"max_len": 80,
"max_char_len": 200
},
"thanks": {
"entrance_enable": true,
"gift_enable": true,
"entrance_copy": "欢迎 {username}",
"gift_copy": "感谢 {username} 送的 {gift_name}",
"lowest_price": 1.0
},
"live2d": {
"enable": true,
"port": 12345
Expand Down
1 change: 0 additions & 1 deletion data/badwords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,6 @@
黄晶
捐肾
乳尖
西游
被插
干拎娘
潘金莲
Expand Down
1 change: 1 addition & 0 deletions data/copywriting/伊卡日语介绍.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
こんにちは、私はAIキャスターで、私の名前はイカロスです。私の声はVITSから合成されていて、私は中国語が苦手なので、日本語で返事をしますので、気にしないでください。私の今のイメージは間違っていますが、未来は変わります。ご来店ありがとうございます。合法的なコンプライアンスであれば、私が知っている限り、私はあなたに答えることができます。
28 changes: 26 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def init_config(self):
# 过滤配置
self.filter_config = config.get("filter")

# 答谢
self.thanks_config = config.get("thanks")

self.chat_type = config.get("chat_type")

self.need_lang = config.get("need_lang")
Expand Down Expand Up @@ -176,6 +179,12 @@ def init_config(self):
self.ui.label_filter_max_len.setToolTip("最长阅读的英文单词数(空格分隔)")
self.ui.label_filter_max_char_len.setToolTip("最长阅读的字符数,双重过滤,避免溢出")

self.ui.label_thanks_entrance_enable.setToolTip("是否启用欢迎用户进入直播间功能")
self.ui.label_thanks_gift_enable.setToolTip("是否启用感谢用户赠送礼物功能")
self.ui.label_thanks_entrance_copy.setToolTip("用户进入直播间的相关文案,请勿动 {username},此字符串用于替换用户名")
self.ui.label_thanks_gift_copy.setToolTip("用户赠送礼物的相关文案,请勿动 {username} 和 {gift_name},此字符串用于替换用户名和礼物名")
self.ui.label_thanks_lowest_price.setToolTip("设置最低答谢礼物的价格(元),低于这个设置的礼物不会触发答谢")

self.ui.label_live2d_enable.setToolTip("启动web服务,用于加载本地Live2D模型")
self.ui.label_live2d_port.setToolTip("web服务运行的端口号,默认:12345,范围:0-65535,没事不要乱改就好")
self.ui.label_live2d_name.setToolTip("模型名称,模型存放于Live2D\live2d-model路径下,请注意路径和模型内容是否匹配")
Expand Down Expand Up @@ -367,6 +376,15 @@ def init_config(self):
self.ui.lineEdit_filter_max_len.setText(str(self.filter_config['max_len']))
self.ui.lineEdit_filter_max_char_len.setText(str(self.filter_config['max_char_len']))

# 答谢
if self.thanks_config['entrance_enable']:
self.ui.checkBox_thanks_entrance_enable.setChecked(True)
if self.thanks_config['gift_enable']:
self.ui.checkBox_thanks_gift_enable.setChecked(True)
self.ui.lineEdit_thanks_entrance_copy.setText(self.thanks_config['entrance_copy'])
self.ui.lineEdit_thanks_gift_copy.setText(self.thanks_config['gift_copy'])
self.ui.lineEdit_thanks_lowest_price.setText(str(self.thanks_config['lowest_price']))

if self.live2d_config['enable']:
self.ui.checkBox_live2d_enable.setChecked(True)
self.ui.lineEdit_live2d_port.setText(str(self.live2d_config['port']))
Expand Down Expand Up @@ -778,8 +796,14 @@ def save(self):
max_char_len = self.ui.lineEdit_filter_max_char_len.text()
config_data["filter"]["max_char_len"] = int(max_char_len)

live2d_enable = self.ui.checkBox_live2d_enable.isChecked()
config_data["live2d"]["enable"] = live2d_enable
# 答谢
config_data["thanks"]["entrance_enable"] = self.ui.checkBox_thanks_entrance_enable.isChecked()
config_data["thanks"]["gift_enable"] = self.ui.checkBox_thanks_gift_enable.isChecked()
config_data["thanks"]["entrance_copy"] = self.ui.lineEdit_thanks_entrance_copy.text()
config_data["thanks"]["gift_copy"] = self.ui.lineEdit_thanks_gift_copy.text()
config_data["thanks"]["lowest_price"] = round(float(self.ui.lineEdit_thanks_lowest_price.text()), 2)

config_data["live2d"]["enable"] = self.ui.checkBox_live2d_enable.isChecked()
live2d_port = self.ui.lineEdit_live2d_port.text()
config_data["live2d"]["port"] = int(live2d_port)
tmp_str = f"var model_name = \"{self.ui.comboBox_live2d_name.currentText()}\";"
Expand Down
Binary file added out/copywriting/伊卡日语介绍.wav
Binary file not shown.
Loading

0 comments on commit aa88232

Please sign in to comment.