代码拉取完成,页面将自动刷新
import time
from bilibili_api import live
from bilibili_api import user
import time as t
from baidu_ai_voice import *
from playsound import playsound
from aip import AipSpeech
import os
//房间号
dm = live.LiveDanmaku(room_display_id="5239322", debug=False, use_wss=True, should_reconnect=True)
//百度智能云控制台的appid api_key...
client = AipSpeech(BAIDUAI_AppID, BAIDUAI_API_Key, BAIDUAI_Secret_Key)
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])}".replace(" ", "").replace(":", "")
if len(message) != 0:
result = client.synthesis(voice, 'zh', 0, {
'vol': 5,
})
if not isinstance(result, dict):
with open('./audio.mp3', 'wb') as f:
f.write(result)
playsound("./audio.mp3")
os.remove("audio.mp3")
if __name__ == '__main__':
connect()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。