Skip to content

Commit

Permalink
feat: 优化播放延迟问题,并新增配置下一首播放的延迟秒数
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Jul 28, 2024
1 parent 6b38676 commit eab4f4b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions xiaomusic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class Config:
remove_id3tag: bool = (
os.getenv("XIAOMUSIC_REMOVE_ID3TAG", "false").lower() == "true"
)
delay_sec: int = int(os.getenv("XIAOMUSIC_DELAY_SEC", 3)) # 下一首歌延迟播放秒数

def append_keyword(self, keys, action):
for key in keys.split(","):
Expand Down
4 changes: 2 additions & 2 deletions xiaomusic/static/debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<meta name="viewport" content="width=device-width">
<title>Debug For XiaoMusic</title>

<link rel="stylesheet" type="text/css" href="/static/style.css?version=1721862430">
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1722127035">
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
<script src="/static/jquery-3.7.1.min.js?version=1721862430"></script>
<script src="/static/jquery-3.7.1.min.js?version=1722127035"></script>

<script>
var vConsole = new window.VConsole();
Expand Down
6 changes: 3 additions & 3 deletions xiaomusic/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<meta name="viewport" content="width=device-width">
<title>小爱音箱操控面板</title>
<script src="/static/jquery-3.7.1.min.js?version=1721862430"></script>
<script src="/static/app.js?version=1721862430"></script>
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1721862430">
<script src="/static/jquery-3.7.1.min.js?version=1722127035"></script>
<script src="/static/app.js?version=1722127035"></script>
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1722127035">

<!--
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion xiaomusic/static/m3u.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>M3U to JSON Converter</title>
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1721862430">
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1722127035">
<!--
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
<script>
Expand Down
9 changes: 6 additions & 3 deletions xiaomusic/static/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<meta name="viewport" content="width=device-width">
<title>小爱音箱操控面板</title>
<script src="/static/jquery-3.7.1.min.js?version=1721862430"></script>
<script src="/static/setting.js?version=1721862430"></script>
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1721862430">
<script src="/static/jquery-3.7.1.min.js?version=1722127035"></script>
<script src="/static/setting.js?version=1722127035"></script>
<link rel="stylesheet" type="text/css" href="/static/style.css?version=1722127035">

<!--
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
Expand Down Expand Up @@ -130,6 +130,9 @@ <h2>小爱音箱设置面板
<label for="public_port">外网访问端口(0表示跟监听端口一致):</label>
<input id="public_port" type="number" value="0"></input>

<label for="delay_sec">下一首歌延迟播放秒数:</label>
<input id="delay_sec" type="number" value="3"></input>

<label for="stop_tts_msg">停止提示音:</label>
<input id="stop_tts_msg" type="text" value="收到,再见"></input>
<label for="keywords_playlocal">播放本地歌曲口令:</label>
Expand Down
4 changes: 1 addition & 3 deletions xiaomusic/static/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ $(function(){

// 初始化显示
for (const key in data) {
if (data.hasOwnProperty(key)) {
const $element = $("#" + key);
if ($element.length && data[key] !== '') {
if ($element.length) {
if (data[key] === true) {
$element.val('true');
} else if (data[key] === false) {
Expand All @@ -79,7 +78,6 @@ $(function(){
$element.val(data[key]);
}
}
}
}

autoSelectOne();
Expand Down
5 changes: 3 additions & 2 deletions xiaomusic/xiaomusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ async def _playmusic(self, name):
self.cur_music = name
self.log.info(f"cur_music {self.cur_music}")
sec, url = await self.xiaomusic.get_music_sec_url(name)
await self.group_force_stop_xiaoai()
# await self.group_force_stop_xiaoai()
self.log.info(f"播放 {url}")
results = await self.group_player_play(url)
if all(ele is None for ele in results):
Expand All @@ -933,6 +933,7 @@ async def _playmusic(self, name):
# 取消组内所有的下一首歌曲的定时器
self.cancel_group_next_timer()
# 设置下一首歌曲的播放定时器
sec = sec + self.config.delay_sec
await self.set_next_music_timeout(sec)

async def do_tts(self, value):
Expand All @@ -941,7 +942,7 @@ async def do_tts(self, value):
self.log.info("do_tts no value")
return

await self.group_force_stop_xiaoai()
# await self.group_force_stop_xiaoai()
await self.text_to_speech(value)

# 最大等8秒
Expand Down

0 comments on commit eab4f4b

Please sign in to comment.