Luigi commited on
Commit
16a76a8
·
1 Parent(s): 3a8fb9a

translate ui to chinese

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +23 -19
src/streamlit_app.py CHANGED
@@ -30,52 +30,56 @@ def get_providers_and_voices(base_dir: Path):
30
  # Main app
31
  def main():
32
  # Configure page for better mobile experience; sidebar collapses nicely on small screens
33
- st.set_page_config(page_title="TTS Samples Player", layout="wide")
34
- st.title("🎵 TTS Samples Player")
 
35
  st.markdown(
36
  """
37
- Select a TTS engine provider and a voice to play the corresponding WAV sample.
38
- Use the sidebar to select provider and voice for better mobile experience.
 
 
 
39
  """
40
  )
41
  # Debugging: show BASE_DIR path
42
  st.sidebar.write(f"BASE_DIR: `{BASE_DIR}`")
43
  providers = get_providers_and_voices(BASE_DIR)
44
  if not providers:
45
- st.warning(f"No providers found in `{BASE_DIR}`. Please ensure the folder exists with subfolders containing .wav files.")
46
  # Optionally show what exists at parent: for debugging
47
  parent = BASE_DIR.parent
48
  if parent.exists():
49
- st.info(f"Contents of parent directory `{parent}`: {sorted([p.name for p in parent.iterdir()])}")
50
  return
51
 
52
  # Sidebar for selection (better for mobile)
53
- st.sidebar.header("Select TTS Sample")
54
  provider_list = sorted(providers.keys())
55
- provider = st.sidebar.selectbox("Provider", options=provider_list)
56
 
57
  voices = providers.get(provider, [])
58
  if not voices:
59
- st.sidebar.info(f"No .wav files under provider `{provider}`.")
60
  return
61
 
62
- voice = st.sidebar.selectbox("Voice", options=voices)
63
 
64
  # Main area shows playback
65
- st.markdown(f"### Playing: **{provider} / {voice}**")
66
  file_path = BASE_DIR / provider / voice
67
  if file_path.is_file():
68
  try:
69
  audio_bytes = file_path.read_bytes()
70
  st.audio(audio_bytes, format="audio/wav")
71
  except Exception as e:
72
- st.error(f"Error loading audio: {e}")
73
  else:
74
- st.error(f"File not found: `{file_path}`")
75
 
76
  # Browse all providers and voices in collapsible sections
77
  st.markdown("---")
78
- st.markdown("#### Browse all samples")
79
  for prov, voice_files in providers.items():
80
  with st.expander(prov, expanded=False):
81
  for vf in voice_files:
@@ -83,16 +87,16 @@ def main():
83
  btn_key = f"play_{prov}_{vf}"
84
  cols = st.columns([3,1])
85
  cols[0].write(vf)
86
- if cols[1].button("Play", key=btn_key):
87
  if path.is_file():
88
  try:
89
  data = path.read_bytes()
90
  st.audio(data, format="audio/wav")
91
- st.write(f"**Playing**: `{prov}/{vf}`")
92
  except Exception as ex:
93
- st.error(f"Error playing file: {ex}")
94
  else:
95
- st.error(f"File not found: {path}")
96
 
97
  if __name__ == "__main__":
98
- main()
 
30
  # Main app
31
  def main():
32
  # Configure page for better mobile experience; sidebar collapses nicely on small screens
33
+ st.set_page_config(page_title="TTS 範例播放器", layout="wide")
34
+ st.title("🎵 TTS 範例播放器")
35
+ # Short introduction for non-tech users
36
  st.markdown(
37
  """
38
+ **此範例示範 TTS 播放以下句子:
39
+ > 八和和牛燒肉專門店。沒有將就,只有講究!
40
+
41
+ 您可以選擇不同的 TTS 提供者與語音,來播放對應的示例音檔。
42
+ 在側邊欄進行選擇,以獲得更佳體驗。
43
  """
44
  )
45
  # Debugging: show BASE_DIR path
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 (better for mobile)
57
+ st.sidebar.header("選擇 TTS 範例")
58
  provider_list = sorted(providers.keys())
59
+ provider = st.sidebar.selectbox("提供者", options=provider_list)
60
 
61
  voices = providers.get(provider, [])
62
  if not voices:
63
+ st.sidebar.info(f"提供者 `{provider}` 底下沒有 .wav 檔案。")
64
  return
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():
72
  try:
73
  audio_bytes = file_path.read_bytes()
74
  st.audio(audio_bytes, format="audio/wav")
75
  except Exception as e:
76
+ st.error(f"載入音訊時出錯: {e}")
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:
 
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()