Spaces:
Sleeping
Sleeping
clean layout
Browse files- src/streamlit_app.py +6 -30
src/streamlit_app.py
CHANGED
@@ -29,7 +29,7 @@ def get_providers_and_voices(base_dir: Path):
|
|
29 |
|
30 |
# Main app
|
31 |
def main():
|
32 |
-
# Configure page for better mobile experience
|
33 |
st.set_page_config(page_title="TTS 範例播放器", layout="wide")
|
34 |
st.title("🎵 TTS 範例播放器")
|
35 |
# Short introduction for non-tech users
|
@@ -38,22 +38,19 @@ def main():
|
|
38 |
**此範例示範 TTS 播放以下句子:
|
39 |
> 八和和牛燒肉專門店。沒有將就,只有講究!
|
40 |
|
41 |
-
|
42 |
-
在側邊欄進行選擇,以獲得更佳體驗。
|
43 |
"""
|
44 |
)
|
45 |
-
|
46 |
-
st.sidebar.write(f"BASE_DIR: `{BASE_DIR}`")
|
47 |
providers = get_providers_and_voices(BASE_DIR)
|
48 |
if not providers:
|
49 |
st.warning(f"未找到任何 TTS 提供者資料夾 `{BASE_DIR}`,請確認資料夾存在,且包含 .wav 檔案。")
|
50 |
-
# Optionally show what exists at parent: for debugging
|
51 |
parent = BASE_DIR.parent
|
52 |
if parent.exists():
|
53 |
st.info(f"上層資料夾內容 `{parent}`: {sorted([p.name for p in parent.iterdir()])}")
|
54 |
return
|
55 |
|
56 |
-
# Sidebar for selection
|
57 |
st.sidebar.header("選擇 TTS 範例")
|
58 |
provider_list = sorted(providers.keys())
|
59 |
provider = st.sidebar.selectbox("提供者", options=provider_list)
|
@@ -65,7 +62,7 @@ def main():
|
|
65 |
|
66 |
voice = st.sidebar.selectbox("語音", options=voices)
|
67 |
|
68 |
-
# Main area shows playback
|
69 |
st.markdown(f"### 播放中:**{provider} / {voice}**")
|
70 |
file_path = BASE_DIR / provider / voice
|
71 |
if file_path.is_file():
|
@@ -77,26 +74,5 @@ def main():
|
|
77 |
else:
|
78 |
st.error(f"找不到檔案: `{file_path}`")
|
79 |
|
80 |
-
# Browse all providers and voices in collapsible sections
|
81 |
-
st.markdown("---")
|
82 |
-
st.markdown("#### 瀏覽所有範例音檔")
|
83 |
-
for prov, voice_files in providers.items():
|
84 |
-
with st.expander(prov, expanded=False):
|
85 |
-
for vf in voice_files:
|
86 |
-
path = BASE_DIR / prov / vf
|
87 |
-
btn_key = f"play_{prov}_{vf}"
|
88 |
-
cols = st.columns([3,1])
|
89 |
-
cols[0].write(vf)
|
90 |
-
if cols[1].button("播放", key=btn_key):
|
91 |
-
if path.is_file():
|
92 |
-
try:
|
93 |
-
data = path.read_bytes()
|
94 |
-
st.audio(data, format="audio/wav")
|
95 |
-
st.write(f"**播放中**:`{prov}/{vf}`")
|
96 |
-
except Exception as ex:
|
97 |
-
st.error(f"播放音檔時出錯: {ex}")
|
98 |
-
else:
|
99 |
-
st.error(f"找不到檔案: {path}")
|
100 |
-
|
101 |
if __name__ == "__main__":
|
102 |
-
main()
|
|
|
29 |
|
30 |
# Main app
|
31 |
def main():
|
32 |
+
# Configure page for better mobile experience
|
33 |
st.set_page_config(page_title="TTS 範例播放器", layout="wide")
|
34 |
st.title("🎵 TTS 範例播放器")
|
35 |
# Short introduction for non-tech users
|
|
|
38 |
**此範例示範 TTS 播放以下句子:
|
39 |
> 八和和牛燒肉專門店。沒有將就,只有講究!
|
40 |
|
41 |
+
請在側邊欄選擇 TTS 提供者與語音,然後播放範例音檔。
|
|
|
42 |
"""
|
43 |
)
|
44 |
+
|
|
|
45 |
providers = get_providers_and_voices(BASE_DIR)
|
46 |
if not providers:
|
47 |
st.warning(f"未找到任何 TTS 提供者資料夾 `{BASE_DIR}`,請確認資料夾存在,且包含 .wav 檔案。")
|
|
|
48 |
parent = BASE_DIR.parent
|
49 |
if parent.exists():
|
50 |
st.info(f"上層資料夾內容 `{parent}`: {sorted([p.name for p in parent.iterdir()])}")
|
51 |
return
|
52 |
|
53 |
+
# Sidebar for selection
|
54 |
st.sidebar.header("選擇 TTS 範例")
|
55 |
provider_list = sorted(providers.keys())
|
56 |
provider = st.sidebar.selectbox("提供者", options=provider_list)
|
|
|
62 |
|
63 |
voice = st.sidebar.selectbox("語音", options=voices)
|
64 |
|
65 |
+
# Main area shows single playback
|
66 |
st.markdown(f"### 播放中:**{provider} / {voice}**")
|
67 |
file_path = BASE_DIR / provider / voice
|
68 |
if file_path.is_file():
|
|
|
74 |
else:
|
75 |
st.error(f"找不到檔案: `{file_path}`")
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
if __name__ == "__main__":
|
78 |
+
main()
|