1 Star 1 Fork 0

codestar/voice_message

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
billi_baidu_voice.py 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
codestar 提交于 2021-05-31 17:55 . rename billi.py to billi_baidu_voice.py.
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/star574/voice_message.git
git@gitee.com:star574/voice_message.git
star574
voice_message
voice_message
master

搜索帮助