lengyue233 commited on
Commit
2dc5ce9
·
verified ·
1 Parent(s): a53df75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -16
app.py CHANGED
@@ -300,12 +300,6 @@ def normalize_text(user_input, use_normalization):
300
  else:
301
  return user_input
302
 
303
- def update_examples():
304
- examples_dir = Path("references")
305
- examples_dir.mkdir(parents=True, exist_ok=True)
306
- example_audios = list_files(examples_dir, AUDIO_EXTENSIONS, recursive=True)
307
- return gr.Dropdown(choices=example_audios + [""])
308
-
309
  def build_app():
310
  with gr.Blocks(theme=gr.themes.Base()) as app:
311
  gr.Markdown(HEADER_MD)
@@ -396,14 +390,21 @@ def build_app():
396
  with gr.Row():
397
  gr.Markdown(
398
  i18n(
399
- "5 to 10 seconds of reference audio, useful for specifying speaker."
400
  )
401
  )
402
- with gr.Row():
403
- reference_id = gr.Textbox(
404
- label=i18n("Reference ID"),
405
- placeholder="Leave empty to use uploaded references",
406
- )
 
 
 
 
 
 
 
407
 
408
  with gr.Row():
409
  use_memory_cache = gr.Radio(
@@ -452,7 +453,6 @@ def build_app():
452
  def inference_wrapper(
453
  text,
454
  normalize,
455
- reference_id,
456
  reference_audio,
457
  reference_text,
458
  max_new_tokens,
@@ -475,7 +475,7 @@ def build_app():
475
  req = ServeTTSRequest(
476
  text=text,
477
  normalize=normalize,
478
- reference_id=reference_id if reference_id else None,
479
  references=references,
480
  max_new_tokens=max_new_tokens,
481
  chunk_length=chunk_length,
@@ -494,13 +494,34 @@ def build_app():
494
 
495
  return None, i18n("No audio generated")
496
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
497
  # Submit
498
  generate.click(
499
  inference_wrapper,
500
  [
501
  refined_text,
502
- normalize,
503
- reference_id,
504
  reference_audio,
505
  reference_text,
506
  max_new_tokens,
 
300
  else:
301
  return user_input
302
 
 
 
 
 
 
 
303
  def build_app():
304
  with gr.Blocks(theme=gr.themes.Base()) as app:
305
  gr.Markdown(HEADER_MD)
 
390
  with gr.Row():
391
  gr.Markdown(
392
  i18n(
393
+ "15 to 60 seconds of reference audio, useful for specifying speaker."
394
  )
395
  )
396
+
397
+ enable_reference_audio = gr.Checkbox(
398
+ label="Enable Reference Audio",
399
+ )
400
+
401
+ # Add dropdown for selecting example audio files
402
+ example_audio_files = [f for f in os.listdir("examples") if f.endswith(".wav")]
403
+ example_audio_dropdown = gr.Dropdown(
404
+ label="Select Example Audio",
405
+ choices=[""] + example_audio_files,
406
+ value=""
407
+ )
408
 
409
  with gr.Row():
410
  use_memory_cache = gr.Radio(
 
453
  def inference_wrapper(
454
  text,
455
  normalize,
 
456
  reference_audio,
457
  reference_text,
458
  max_new_tokens,
 
475
  req = ServeTTSRequest(
476
  text=text,
477
  normalize=normalize,
478
+ reference_id=None,
479
  references=references,
480
  max_new_tokens=max_new_tokens,
481
  chunk_length=chunk_length,
 
494
 
495
  return None, i18n("No audio generated")
496
 
497
+ def select_example_audio(audio_file):
498
+ if audio_file:
499
+ audio_path = os.path.join("examples", audio_file)
500
+ lab_file = os.path.splitext(audio_file)[0] + ".lab"
501
+ lab_path = os.path.join("examples", lab_file)
502
+
503
+ if os.path.exists(lab_path):
504
+ with open(lab_path, "r", encoding="utf-8") as f:
505
+ lab_content = f.read().strip()
506
+ else:
507
+ lab_content = ""
508
+
509
+ return audio_path, lab_content, True
510
+ return None, "", False
511
+
512
+ # Connect the dropdown to update reference audio and text
513
+ example_audio_dropdown.change(
514
+ fn=select_example_audio,
515
+ inputs=[example_audio_dropdown],
516
+ outputs=[reference_audio, reference_text, enable_reference_audio]
517
+ )
518
+
519
  # Submit
520
  generate.click(
521
  inference_wrapper,
522
  [
523
  refined_text,
524
+ enable_reference_audio,
 
525
  reference_audio,
526
  reference_text,
527
  max_new_tokens,