MZhao-LEGION commited on
Commit
657d73c
1 Parent(s): 99c9666

support change Voices

Browse files
Files changed (3) hide show
  1. app.py +6 -3
  2. css/style.css +57 -0
  3. presets.py +7 -3
app.py CHANGED
@@ -8,8 +8,11 @@ with gr.Blocks(css=customCSS) as demo:
8
  exceed_flag = gr.State(value=False)
9
  tmp_string = gr.Textbox(value="", visible=False)
10
  character_area = gr.HTML(get_character_html("你好呀!我现在支持多语言了呢!"), elem_id="character_area")
 
 
 
11
  with gr.Tab("Speak", elem_id="tab-speak"):
12
- speak_input = gr.Textbox(lines=1, label="Talking Flower will say:", placeholder="Support Chinese, English and Japanese...", elem_classes="wonder-card input_text", elem_id="speak_input")
13
  speak_button = gr.Button("Speak!", elem_id="speak_button", elem_classes="main-button wonder-card")
14
  example_category = gr.Examples(["夸夸你 | Praise", "游戏台词 | Scripts", "玩梗 | Meme"], inputs=[tmp_string], elem_id="examples")
15
  with gr.Tab("Chat", elem_id="tab-chat"):
@@ -27,12 +30,12 @@ with gr.Blocks(css=customCSS) as demo:
27
  )
28
  speak_input.submit(submit_lock_fn, show_progress=False).then(
29
  speak_fn,
30
- inputs=[speak_input, exceed_flag],
31
  outputs=[audio_output, character_area, exceed_flag, speak_button],
32
  )
33
  speak_button.click(submit_lock_fn, show_progress=False).then(
34
  speak_fn,
35
- inputs=[speak_input, exceed_flag],
36
  outputs=[audio_output, character_area, exceed_flag, speak_button],
37
  )
38
 
 
8
  exceed_flag = gr.State(value=False)
9
  tmp_string = gr.Textbox(value="", visible=False)
10
  character_area = gr.HTML(get_character_html("你好呀!我现在支持多语言了呢!"), elem_id="character_area")
11
+ with gr.Row(elem_id="tools_area"):
12
+ api_key_input = gr.Textbox(lines=1, max_lines=1, label="API Key:", placeholder="Comming Soon...", elem_classes="wonder-card", elem_id="api_key_input")
13
+ voice_list = gr.Dropdown(choices=["Chinese", "English", "Japanese"], value="Chinese", label="Choose voice:", elem_id="voice_list", elem_classes="wonder-card")
14
  with gr.Tab("Speak", elem_id="tab-speak"):
15
+ speak_input = gr.Textbox(lines=1, max_lines=4, label="Talking Flower will say:", placeholder="Support Chinese, English and Japanese...", elem_classes="wonder-card input_text", elem_id="speak_input")
16
  speak_button = gr.Button("Speak!", elem_id="speak_button", elem_classes="main-button wonder-card")
17
  example_category = gr.Examples(["夸夸你 | Praise", "游戏台词 | Scripts", "玩梗 | Meme"], inputs=[tmp_string], elem_id="examples")
18
  with gr.Tab("Chat", elem_id="tab-chat"):
 
30
  )
31
  speak_input.submit(submit_lock_fn, show_progress=False).then(
32
  speak_fn,
33
+ inputs=[speak_input, exceed_flag, voice_list],
34
  outputs=[audio_output, character_area, exceed_flag, speak_button],
35
  )
36
  speak_button.click(submit_lock_fn, show_progress=False).then(
37
  speak_fn,
38
+ inputs=[speak_input, exceed_flag, voice_list],
39
  outputs=[audio_output, character_area, exceed_flag, speak_button],
40
  )
41
 
css/style.css CHANGED
@@ -33,6 +33,7 @@
33
  --base-space: 8px;
34
 
35
  --card-width: 95%;
 
36
  }
37
 
38
  @media screen and (min-width: 640px) {
@@ -40,6 +41,7 @@
40
  --gutter-width:24px;
41
 
42
  --card-width: 42%;
 
43
  }
44
  }
45
 
@@ -63,6 +65,7 @@ gradio-app {
63
  background-position: center center !important;
64
  }
65
 
 
66
  #character_area {
67
  width: var(--card-width) !important;
68
  align-self: center;
@@ -109,6 +112,60 @@ gradio-app {
109
  height: 10rem;
110
  }
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  /* Tabs */
113
  .tabs {
114
  width: var(--card-width) !important;
 
33
  --base-space: 8px;
34
 
35
  --card-width: 95%;
36
+ --voice-flex: 1;
37
  }
38
 
39
  @media screen and (min-width: 640px) {
 
41
  --gutter-width:24px;
42
 
43
  --card-width: 42%;
44
+ --voice-flex: 0.6;
45
  }
46
  }
47
 
 
65
  background-position: center center !important;
66
  }
67
 
68
+ /* Character Area */
69
  #character_area {
70
  width: var(--card-width) !important;
71
  align-self: center;
 
112
  height: 10rem;
113
  }
114
 
115
+ /* Tools Area */
116
+ #tools_area {
117
+ width: var(--card-width) !important;
118
+ align-self: center;
119
+ }
120
+ #tools_area .form {
121
+ display: flex;
122
+ flex-direction: row;
123
+ flex-wrap: wrap;
124
+ align-items: center;
125
+ justify-content: center;
126
+ align-content: center;
127
+ align-items: center;
128
+ }
129
+ #api_key_input {
130
+ flex-grow: 1;
131
+ }
132
+ #voice_list {
133
+ flex-grow: var(--voice-flex);
134
+ }
135
+ #api_key_input input {
136
+ margin: 0 !important;
137
+ padding: 6px 12px 6px 12px;
138
+ }
139
+ #api_key_input label span {
140
+ font-family: var(--font-heading) !important;
141
+ margin: 0;
142
+ width: 5rem;
143
+ }
144
+ #api_key_input label,
145
+ #voice_list label {
146
+ display: flex;
147
+ align-items: center;
148
+ flex-wrap: nowrap;
149
+ align-content: center;
150
+ justify-content: center;
151
+ flex-direction: row;
152
+ }
153
+ #voice_list label span {
154
+ font-family: var(--font-heading) !important;
155
+ margin: 0;
156
+ width: 7rem;
157
+ }
158
+ #voice_list input {
159
+ width: 4rem !important;
160
+ margin: 0 !important;
161
+ }
162
+ #voice_list .icon-wrap {
163
+ margin: 0 !important;
164
+ }
165
+ #voice_list ul {
166
+ width: 5rem !important;
167
+ }
168
+
169
  /* Tabs */
170
  .tabs {
171
  width: var(--card-width) !important;
presets.py CHANGED
@@ -43,6 +43,10 @@ def speak_fn(
43
  interval_between_para=0.2, # 段间间隔
44
  interval_between_sent=1, # 句间间隔
45
  ):
 
 
 
 
46
  audio_list = []
47
  while text.find("\n\n") != -1:
48
  text = text.replace("\n\n", "\n")
@@ -86,7 +90,7 @@ def speak_fn(
86
  break
87
  skip_start = (idx != 0) and skip_start
88
  skip_end = (idx != len(sentences_list) - 1) and skip_end
89
- print(text_to_generate, lang_to_generate)
90
 
91
  with torch.no_grad():
92
  for i, piece in enumerate(text_to_generate):
@@ -176,9 +180,9 @@ def submit_lock_fn():
176
 
177
 
178
  def init_fn():
179
- gr.Info("2023-11-28: 支持多语言啦!闲聊花花现在能说中、英、日语啦!")
180
  # gr.Info("2023-11-24: 优化长句生成效果;增加示例;更新了一些小彩蛋;画了一些大饼)")
181
- gr.Info("Support languages: Chinese, English, Japanese. 欢迎在 Community 中提建议~")
182
 
183
  index = random.randint(1,7)
184
  welcome_text = get_sentence("Welcome", index)
 
43
  interval_between_para=0.2, # 段间间隔
44
  interval_between_sent=1, # 句间间隔
45
  ):
46
+ if speaker == "Chinese": speaker = "TalkFlower_CNzh"
47
+ elif speaker == "English": speaker = "TalkFlower_USen"
48
+ elif speaker == "Japanese": speaker = "TalkFlower_JPja"
49
+ else: speaker = "TalkFlower_CNzh"
50
  audio_list = []
51
  while text.find("\n\n") != -1:
52
  text = text.replace("\n\n", "\n")
 
90
  break
91
  skip_start = (idx != 0) and skip_start
92
  skip_end = (idx != len(sentences_list) - 1) and skip_end
93
+ logging.info(f"{speaker[-4:]}: {text_to_generate}{lang_to_generate}")
94
 
95
  with torch.no_grad():
96
  for i, piece in enumerate(text_to_generate):
 
180
 
181
 
182
  def init_fn():
183
+ gr.Info("2023-11-28: 支持多语言(中、英、日)!支持更换音色!")
184
  # gr.Info("2023-11-24: 优化长句生成效果;增加示例;更新了一些小彩蛋;画了一些大饼)")
185
+ # gr.Info("Support languages: Chinese, English, Japanese. 欢迎在 Community 中提建议~")
186
 
187
  index = random.randint(1,7)
188
  welcome_text = get_sentence("Welcome", index)