Skip to content

Commit

Permalink
新增 斗鱼平台的接入(初步接入,仅有弹幕数据的监听)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikaros-521 committed Aug 13, 2023
1 parent 397ce35 commit d5b4f0a
Show file tree
Hide file tree
Showing 10 changed files with 340 additions and 73 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ AI Vtuber是一个由 ChatterBot/GPT/Claude/langchain本地or云端/chatglm/text
- [抖音版](#%E6%8A%96%E9%9F%B3%E7%89%88)
- [抖音版_旧版(不稳定)](#%E6%8A%96%E9%9F%B3%E7%89%88_%E6%97%A7%E7%89%88%E4%B8%8D%E7%A8%B3%E5%AE%9A)
- [快手版](#%E5%BF%AB%E6%89%8B%E7%89%88)
- [斗鱼版](#%E6%96%97%E9%B1%BC%E7%89%88)
- [聊天模式](#%E8%81%8A%E5%A4%A9%E6%A8%A1%E5%BC%8F)
- [🃏效果图](#%E6%95%88%E6%9E%9C%E5%9B%BE)
- [GUI界面](#gui%E7%95%8C%E9%9D%A2)
Expand Down Expand Up @@ -81,6 +82,7 @@ AI Vtuber是一个由 ChatterBot/GPT/Claude/langchain本地or云端/chatglm/text
- [b站直播监听](#b%E7%AB%99%E7%9B%B4%E6%92%AD%E7%9B%91%E5%90%AC)
- [<span id="dy">抖音弹幕获取</span>](#span-iddy%E6%8A%96%E9%9F%B3%E5%BC%B9%E5%B9%95%E8%8E%B7%E5%8F%96span)
- [快手弹幕获取](#%E5%BF%AB%E6%89%8B%E5%BC%B9%E5%B9%95%E8%8E%B7%E5%8F%96)
- [斗鱼直播监听](#%E6%96%97%E9%B1%BC%E7%9B%B4%E6%92%AD%E7%9B%91%E5%90%AC)
- [ChatGPT](#chatgpt)
- [Claude](#claude)
- [ChatGLM](#chatglm)
Expand Down Expand Up @@ -628,6 +630,17 @@ ps:依赖[golang](https://go.dev/dl/)环境,还没有的话,手动补一补[

运行 `python main.py`

### 斗鱼版

在命令行中使用以下命令安装所需库:
```
pip install -r requirements_douyu.txt
```

运行 `python main.py`

打开您的浏览器,找到您需要监听的直播间,然后按F12打开开发者工具,点击Console(控制台),复制[Scripts/直播ws脚本/douyu_ws_client.js](./Scripts/%E7%9B%B4%E6%92%ADws%E8%84%9A%E6%9C%AC/douyu_ws_client.js)脚本中的内容,粘贴到控制台,回车运行,启动监听服务。

### 聊天模式

在命令行中使用以下命令安装所需库:
Expand Down Expand Up @@ -827,6 +840,9 @@ D:\GitHub_pro\AI-Vtuber-20230: can't open file 'D:\\GitHub_pro\\AI-Vtuber-20230

`ks_old.py`旧版本:[kuaishou-live](https://github.com/YunzhiYike/kuaishou-live)

### 斗鱼直播监听
借鉴[Live-Barrage](https://github.com/XiaoXinYo/Live-Barrage)

### ChatGPT
官网:[https://chat.openai.com/chat](https://chat.openai.com/chat)
openai后台:[https://platform.openai.com/](https://platform.openai.com/)
Expand Down Expand Up @@ -1063,6 +1079,7 @@ out_audio, out_sr, n_frames = svc_model.infer(spk, tran, raw_path)
`pip install -r requirements_bilibili.txt -i https://pypi.tuna.tsinghua.edu.cn/simple`
`pip install -r requirements_dy.txt -i https://pypi.tuna.tsinghua.edu.cn/simple`
`pip install -r requirements_ks.txt -i https://pypi.tuna.tsinghua.edu.cn/simple`
`pip install -r requirements_douyu.txt -i https://pypi.tuna.tsinghua.edu.cn/simple`
4、安装chatterbot(可选)
`pip install spacy SQLAlchemy==1.3.24 -i https://pypi.tuna.tsinghua.edu.cn/simple`
前提是你在当前目录下有clone chatterbot的项目(自行调整路径关系)
Expand Down Expand Up @@ -1384,6 +1401,9 @@ cmd输入命令即可:`doctoc /path/to/file`
### 2023-08-11
- 过滤板块 新增遗忘保留数的配置项,从默认的1个数改为可以根据自定义配置保留,在定时触发后依次响应。

### 2023-08-12
- 新增 斗鱼平台的接入(初步接入,仅有弹幕数据的监听)

</details>


Expand Down
2 changes: 2 additions & 0 deletions Scripts/2-2.安装依赖.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ chcp 65001
Miniconda3\python.exe -m pip install -r requirements_bilibili.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
Miniconda3\python.exe -m pip install -r requirements_dy.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
Miniconda3\python.exe -m pip install -r requirements_ks.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
Miniconda3\python.exe -m pip install -r requirements_douyu.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
Miniconda3\python.exe -m pip install -r requirements_talk.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
Miniconda3\python.exe -m pip install -r requirements_bilibili.txt -i https://pypi.python.org/simple/
Miniconda3\python.exe -m pip install -r requirements_dy.txt -i https://pypi.python.org/simple/
Miniconda3\python.exe -m pip install -r requirements_ks.txt -i https://pypi.python.org/simple/
Miniconda3\python.exe -m pip install -r requirements_douyu.txt -i https://pypi.python.org/simple/
Miniconda3\python.exe -m pip install -r requirements_talk.txt -i https://pypi.python.org/simple/

echo 如果都成功了,那没事了,如果有失败的,请手动补装
Expand Down
3 changes: 3 additions & 0 deletions Scripts/直播ws脚本/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
此文件夹存放直播弹幕监听的JS脚本。
如何使用?
浏览器打开你需要监听的直播间,然后F12打开控制台,粘贴脚本里的代码到控制台,回车运行
89 changes: 89 additions & 0 deletions Scripts/直播ws脚本/douyu_ws_client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
let socket = null;

function connectWebSocket() {
// 创建 WebSocket 连接,适配服务端
socket = new WebSocket("ws://127.0.0.1:5000");

// 当连接建立时触发
socket.addEventListener("open", event => {
console.log("ws连接打开");

// 向服务器发送一条消息
// socket.send("ws连接成功");
});

// 当收到消息时触发
socket.addEventListener("message", event => {
console.log("收到服务器数据:", event.data);
});

// 当连接关闭时触发
socket.addEventListener("close", event => {
console.log("WS连接关闭");

// 重连
setTimeout(() => {
connectWebSocket();
}, 1000); // 延迟 1 秒后重连
});
}

// 初始连接
connectWebSocket();


// 选择需要观察变化的节点
const targetNode = document.querySelector('.Barrage-list');

// 创建观察器实例
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
// 这里处理新增的DOM元素
if(mutation.type === 'childList') {
mutation.addedNodes.forEach(node => {
// 判断是否是新增的弹幕消息
if(node.classList.contains('Barrage-listItem')) {
// 新增的动态DOM元素处理
// console.log('Added node:', node);

const spans = node.getElementsByTagName('span');

let username = "";
let content = "";

for (let span of spans) {
if (span.classList.contains('Barrage-nickName')) {
const targetSpan = span;
// 获取用户名
username = targetSpan.textContent.trim().slice(0, -1);
} else if (span.classList.contains('Barrage-content')) {
const targetSpan = span;
// 获取弹幕内容
content = targetSpan.textContent.trim();
}
}

// 获取到弹幕数据
if (username != "" && content != "") {
const data = {
type: "commit",
username: username,
content: content
};
console.log(data);
socket.send(JSON.stringify(data));
}
}
})
}
});
});

// 配置观察选项
const config = {
childList: true,
subtree: true
};

// 开始观察
observer.observe(targetNode, config);
20 changes: 1 addition & 19 deletions UI_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def setupUi(self, MainWindow):
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, -1614, 980, 8913))
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 980, 8913))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayout = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout.setContentsMargins(35, 20, 35, 20)
Expand Down Expand Up @@ -209,10 +209,6 @@ def setupUi(self, MainWindow):
self.comboBox_platform = QtWidgets.QComboBox(self.formWidget)
self.comboBox_platform.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.comboBox_platform.setObjectName("comboBox_platform")
self.comboBox_platform.addItem("")
self.comboBox_platform.addItem("")
self.comboBox_platform.addItem("")
self.comboBox_platform.addItem("")
self.gridLayout.addWidget(self.comboBox_platform, 0, 1, 1, 1)
self.label_chat_type = QtWidgets.QLabel(self.formWidget)
self.label_chat_type.setObjectName("label_chat_type")
Expand Down Expand Up @@ -438,11 +434,6 @@ def setupUi(self, MainWindow):
self.comboBox_audio_synthesis_type = QtWidgets.QComboBox(self.formWidget)
self.comboBox_audio_synthesis_type.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.comboBox_audio_synthesis_type.setObjectName("comboBox_audio_synthesis_type")
self.comboBox_audio_synthesis_type.addItem("")
self.comboBox_audio_synthesis_type.addItem("")
self.comboBox_audio_synthesis_type.addItem("")
self.comboBox_audio_synthesis_type.addItem("")
self.comboBox_audio_synthesis_type.addItem("")
self.gridLayout.addWidget(self.comboBox_audio_synthesis_type, 10, 1, 1, 1)
self.groupBox_filter = QtWidgets.QGroupBox(self.formWidget)
self.groupBox_filter.setStyleSheet("")
Expand Down Expand Up @@ -1755,10 +1746,6 @@ def retranslateUi(self, MainWindow):
self.checkBox_audio_random_speed_copywriting_enable.setText(_translate("MainWindow", "启用"))
self.label_audio_random_speed_copywriting_speed_min.setText(_translate("MainWindow", "速度下限"))
self.label_audio_random_speed_copywriting_speed_max.setText(_translate("MainWindow", "速度上限"))
self.comboBox_platform.setItemText(0, _translate("MainWindow", "哔哩哔哩"))
self.comboBox_platform.setItemText(1, _translate("MainWindow", "抖音"))
self.comboBox_platform.setItemText(2, _translate("MainWindow", "快手"))
self.comboBox_platform.setItemText(3, _translate("MainWindow", "聊天模式-谷歌"))
self.label_chat_type.setText(_translate("MainWindow", "聊天类型"))
self.groupBox_read_user_name.setTitle(_translate("MainWindow", "念用户名"))
self.label_read_user_name_reply_before.setText(_translate("MainWindow", "前置回复"))
Expand Down Expand Up @@ -1828,11 +1815,6 @@ def retranslateUi(self, MainWindow):
self.label_local_qa_text_type.setText(_translate("MainWindow", "文本问答算法类型"))
self.comboBox_local_qa_text_type.setItemText(0, _translate("MainWindow", "自定义json"))
self.comboBox_local_qa_text_type.setItemText(1, _translate("MainWindow", "一问一答"))
self.comboBox_audio_synthesis_type.setItemText(0, _translate("MainWindow", "Edge-TTS"))
self.comboBox_audio_synthesis_type.setItemText(1, _translate("MainWindow", "VITS-Fast"))
self.comboBox_audio_synthesis_type.setItemText(2, _translate("MainWindow", "elevenlabs"))
self.comboBox_audio_synthesis_type.setItemText(3, _translate("MainWindow", "genshinvoice_top"))
self.comboBox_audio_synthesis_type.setItemText(4, _translate("MainWindow", "bark_gui"))
self.groupBox_filter.setTitle(_translate("MainWindow", "过滤"))
self.label_filter_schedule_forget_duration.setText(_translate("MainWindow", "定时遗忘间隔"))
self.label_filter_talk_forget_duration.setText(_translate("MainWindow", "聊天遗忘间隔"))
Expand Down
Binary file modified docs/AI Vtuber.xmind
Binary file not shown.
Loading

0 comments on commit d5b4f0a

Please sign in to comment.