代码拉取完成,页面将自动刷新
import time
from bilibili_api import live
from bilibili_api import user
import time as t
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty("rate", "100")
engine.setProperty("volume", "1.0")
dm = live.LiveDanmaku(room_display_id="5239322", debug=False, use_wss=True, should_reconnect=True)
def connect():
dm.connect()
@dm.on("DANMU_MSG") # 指定事件名
def on_danmu(msg):
if "info" in str(msg):
info = msg["data"]["info"]
message = str(info[2][1]) + ": " + str(info[1])
print("【弹幕】 from " + message)
# engine.Speak(f"{str(info[2][1])} 说: {str(info[1])}")
# t.sleep(1)
voice = f"{str(info[2][1])} 说: {str(info[1])}"
engine.say(voice)
engine.runAndWait()
if __name__ == '__main__':
connect()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。