Spaces:
Running on Zero
Running on Zero
Commit ·
a775af4
1
Parent(s): 4a8295e
- .gitignore +1 -0
- app.py +215 -211
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
__pycache__
|
app.py
CHANGED
|
@@ -7,9 +7,11 @@ import soundfile as sf
|
|
| 7 |
import tempfile
|
| 8 |
import os
|
| 9 |
import re
|
|
|
|
| 10 |
|
| 11 |
# Global variables to persist across requests
|
| 12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 13 |
model = None
|
| 14 |
processor = None
|
| 15 |
current_model_id = None
|
|
@@ -145,6 +147,7 @@ def load_audio_file(filepath, target_sr=24000):
|
|
| 145 |
print(f"Error loading audio {filepath}: {e}")
|
| 146 |
return None
|
| 147 |
|
|
|
|
| 148 |
def generate_simple_audio(text, speaker_id):
|
| 149 |
"""Generate simple text-to-speech"""
|
| 150 |
global model, processor
|
|
@@ -170,6 +173,7 @@ def generate_simple_audio(text, speaker_id):
|
|
| 170 |
except Exception as e:
|
| 171 |
return None, f"Error: {str(e)}"
|
| 172 |
|
|
|
|
| 173 |
def generate_context_audio(text, speaker_id, context_text, context_audio_file):
|
| 174 |
"""Generate audio with context"""
|
| 175 |
global model, processor
|
|
@@ -250,6 +254,7 @@ def extract_audio_output(audio_output):
|
|
| 250 |
print(f"Error extracting audio: {e}")
|
| 251 |
return np.array([])
|
| 252 |
|
|
|
|
| 253 |
def generate_conversation(speaker_a, speaker_b, speaker_a_audio, speaker_a_text,
|
| 254 |
speaker_b_audio, speaker_b_text, dialogue_text,
|
| 255 |
split_sentences_flag, use_style, progress=gr.Progress()):
|
|
@@ -390,15 +395,16 @@ def generate_conversation(speaker_a, speaker_b, speaker_a_audio, speaker_a_text,
|
|
| 390 |
return None, f"Error: {str(e)}"
|
| 391 |
|
| 392 |
# Initialize with default model
|
|
|
|
| 393 |
def initialize_default_model():
|
| 394 |
"""Initialize the default model on startup"""
|
| 395 |
default_model_name = list(MODELS.keys())[0]
|
| 396 |
load_model(default_model_name)
|
| 397 |
|
| 398 |
# Create interface
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
title="
|
| 402 |
css="""
|
| 403 |
.dhivehi-text textarea {
|
| 404 |
font-size: 18px !important;
|
|
@@ -415,237 +421,235 @@ def create_interface():
|
|
| 415 |
}
|
| 416 |
"""
|
| 417 |
) as app:
|
| 418 |
-
gr.
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
model_info = gr.Textbox(
|
| 428 |
-
value=get_model_info(),
|
| 429 |
-
label="Model Status",
|
| 430 |
-
interactive=False
|
| 431 |
-
)
|
| 432 |
-
|
| 433 |
-
def change_model(model_name):
|
| 434 |
-
success = load_model(model_name)
|
| 435 |
-
if success:
|
| 436 |
-
choices = get_speaker_choices()
|
| 437 |
-
# Generate new speaker display choices for the new model
|
| 438 |
-
current_prompts = get_current_speaker_prompts()
|
| 439 |
-
new_speaker_choices = [(f"{prompt_data['speaker_id']}: {prompt_data['name']}", prompt_data['speaker_id'])
|
| 440 |
-
for prompt_key, prompt_data in current_prompts.items()]
|
| 441 |
-
display_choices = [choice[0] for choice in new_speaker_choices]
|
| 442 |
-
|
| 443 |
-
return (
|
| 444 |
-
gr.update(value=get_model_info()),
|
| 445 |
-
gr.update(choices=choices, value=choices[0]),
|
| 446 |
-
gr.update(choices=choices, value=choices[1] if len(choices) > 1 else choices[0]),
|
| 447 |
-
# Update simple generation speaker radio
|
| 448 |
-
gr.update(choices=display_choices, value=display_choices[0] if display_choices else "0: Speaker"),
|
| 449 |
-
# Update context generation speaker radio
|
| 450 |
-
gr.update(choices=display_choices, value=display_choices[0] if display_choices else "0: Speaker")
|
| 451 |
)
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
gr.update(),
|
| 457 |
-
gr.update()
|
| 458 |
-
)
|
| 459 |
-
|
| 460 |
-
with gr.Tabs():
|
| 461 |
-
# Simple Generation
|
| 462 |
-
with gr.TabItem("🎯 Simple Generation"):
|
| 463 |
-
gr.Markdown("### Generate speech from text without context")
|
| 464 |
-
|
| 465 |
-
with gr.Row():
|
| 466 |
-
with gr.Column():
|
| 467 |
-
simple_text = gr.Textbox(
|
| 468 |
-
label="Text to Generate (Dhivehi)",
|
| 469 |
-
placeholder="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
| 470 |
-
value="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
| 471 |
-
lines=3,
|
| 472 |
-
elem_classes=["dhivehi-text"]
|
| 473 |
-
)
|
| 474 |
-
# Generate speaker choices from current model's speaker prompts
|
| 475 |
-
current_prompts = get_current_speaker_prompts()
|
| 476 |
-
speaker_choices = [(f"{prompt_data['speaker_id']}: {prompt_data['name']}", prompt_data['speaker_id'])
|
| 477 |
-
for prompt_key, prompt_data in current_prompts.items()]
|
| 478 |
-
simple_speaker = gr.Radio(
|
| 479 |
-
choices=[choice[0] for choice in speaker_choices],
|
| 480 |
-
label="Speaker",
|
| 481 |
-
value=speaker_choices[0][0] if speaker_choices else "0: Speaker"
|
| 482 |
-
)
|
| 483 |
-
simple_btn = gr.Button("🎵 Generate", variant="primary")
|
| 484 |
-
|
| 485 |
-
with gr.Column():
|
| 486 |
-
simple_audio = gr.Audio(label="Generated Audio")
|
| 487 |
-
simple_status = gr.Textbox(label="Status", interactive=False)
|
| 488 |
-
|
| 489 |
-
def simple_generate_with_mapping(text, speaker_display):
|
| 490 |
-
# Extract speaker ID from display text (e.g., "0: Female Speaker 01" -> "0")
|
| 491 |
-
speaker_id = speaker_display.split(":")[0]
|
| 492 |
-
return generate_simple_audio(text, speaker_id)
|
| 493 |
-
|
| 494 |
-
simple_btn.click(
|
| 495 |
-
simple_generate_with_mapping,
|
| 496 |
-
inputs=[simple_text, simple_speaker],
|
| 497 |
-
outputs=[simple_audio, simple_status]
|
| 498 |
)
|
| 499 |
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
value="އައިލީޝް އޭނާއަތަށް ލިބުނީ އެންމެ ނުވަ މަހުގަ",
|
| 510 |
-
lines=2,
|
| 511 |
-
elem_classes=["dhivehi-text"]
|
| 512 |
-
)
|
| 513 |
-
context_audio = gr.Audio(
|
| 514 |
-
label="Context Audio",
|
| 515 |
-
type="filepath"
|
| 516 |
-
)
|
| 517 |
-
target_text = gr.Textbox(
|
| 518 |
-
label="Text to Generate",
|
| 519 |
-
placeholder="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
| 520 |
-
value="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
| 521 |
-
lines=3,
|
| 522 |
-
elem_classes=["dhivehi-text"]
|
| 523 |
-
)
|
| 524 |
-
# Generate speaker choices for context generation
|
| 525 |
-
context_speaker = gr.Radio(
|
| 526 |
-
choices=[choice[0] for choice in speaker_choices],
|
| 527 |
-
label="Speaker",
|
| 528 |
-
value=speaker_choices[0][0] if speaker_choices else "0: Speaker"
|
| 529 |
-
)
|
| 530 |
-
context_btn = gr.Button("🎵 Generate with Context", variant="primary")
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
|
|
|
|
|
|
| 545 |
)
|
| 546 |
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
gr.
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
speaker_a = gr.Dropdown(
|
| 553 |
-
choices=get_speaker_choices(),
|
| 554 |
-
label="Speaker A",
|
| 555 |
-
value=get_speaker_choices()[0]
|
| 556 |
-
)
|
| 557 |
-
speaker_b = gr.Dropdown(
|
| 558 |
-
choices=get_speaker_choices(),
|
| 559 |
-
label="Speaker B",
|
| 560 |
-
value=get_speaker_choices()[1] if len(get_speaker_choices()) > 1 else get_speaker_choices()[0]
|
| 561 |
-
)
|
| 562 |
-
|
| 563 |
-
with gr.Accordion("🎵 Audio Style References", open=False):
|
| 564 |
with gr.Row():
|
| 565 |
with gr.Column():
|
| 566 |
-
gr.
|
| 567 |
-
|
| 568 |
-
type="filepath",
|
| 569 |
-
label="Speaker A Audio Style"
|
| 570 |
-
)
|
| 571 |
-
speaker_a_text = gr.Textbox(
|
| 572 |
-
label="Speaker A Context Text",
|
| 573 |
-
lines=2,
|
| 574 |
placeholder="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
|
|
|
|
|
|
| 575 |
elem_classes=["dhivehi-text"]
|
| 576 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
|
| 578 |
with gr.Column():
|
| 579 |
-
gr.
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 586 |
lines=2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
placeholder="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
|
|
|
|
|
|
| 588 |
elem_classes=["dhivehi-text"]
|
| 589 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 590 |
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
)
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 599 |
)
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
change_model,
|
| 624 |
-
inputs=[model_dropdown],
|
| 625 |
-
outputs=[model_info, speaker_a, speaker_b, simple_speaker, context_speaker]
|
| 626 |
-
)
|
| 627 |
|
| 628 |
-
gr.Markdown(f"""
|
| 629 |
-
---
|
| 630 |
-
**Current Model:** {get_model_info()}
|
| 631 |
-
|
| 632 |
-
**Tips:**
|
| 633 |
-
- Simple: Basic text-to-speech
|
| 634 |
-
- Context: Use reference audio for voice consistency
|
| 635 |
-
- Conversation: Multi-speaker dialogues with style control
|
| 636 |
-
|
| 637 |
-
**Issues:**
|
| 638 |
-
- Context: Context breaks sometimes. Adding multiple context audio seems to make it work, or adding previous generation to the context helps.
|
| 639 |
-
- Audio: Sometimes the generated audio is not in sync with the text.
|
| 640 |
-
- Long sentences: Generated long sentences seems sped up.
|
| 641 |
-
- Repeating words: Generated text sometimes repeats words.
|
| 642 |
-
""")
|
| 643 |
-
|
| 644 |
-
return app
|
| 645 |
-
|
| 646 |
if __name__ == "__main__":
|
| 647 |
# Initialize default model on startup
|
| 648 |
initialize_default_model()
|
| 649 |
|
| 650 |
-
app = create_interface()
|
| 651 |
app.launch(share=False)
|
|
|
|
| 7 |
import tempfile
|
| 8 |
import os
|
| 9 |
import re
|
| 10 |
+
import spaces
|
| 11 |
|
| 12 |
# Global variables to persist across requests
|
| 13 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 14 |
+
print ("Device:", device)
|
| 15 |
model = None
|
| 16 |
processor = None
|
| 17 |
current_model_id = None
|
|
|
|
| 147 |
print(f"Error loading audio {filepath}: {e}")
|
| 148 |
return None
|
| 149 |
|
| 150 |
+
@spaces.GPU
|
| 151 |
def generate_simple_audio(text, speaker_id):
|
| 152 |
"""Generate simple text-to-speech"""
|
| 153 |
global model, processor
|
|
|
|
| 173 |
except Exception as e:
|
| 174 |
return None, f"Error: {str(e)}"
|
| 175 |
|
| 176 |
+
@spaces.GPU
|
| 177 |
def generate_context_audio(text, speaker_id, context_text, context_audio_file):
|
| 178 |
"""Generate audio with context"""
|
| 179 |
global model, processor
|
|
|
|
| 254 |
print(f"Error extracting audio: {e}")
|
| 255 |
return np.array([])
|
| 256 |
|
| 257 |
+
@spaces.GPU
|
| 258 |
def generate_conversation(speaker_a, speaker_b, speaker_a_audio, speaker_a_text,
|
| 259 |
speaker_b_audio, speaker_b_text, dialogue_text,
|
| 260 |
split_sentences_flag, use_style, progress=gr.Progress()):
|
|
|
|
| 395 |
return None, f"Error: {str(e)}"
|
| 396 |
|
| 397 |
# Initialize with default model
|
| 398 |
+
@spaces.GPU
|
| 399 |
def initialize_default_model():
|
| 400 |
"""Initialize the default model on startup"""
|
| 401 |
default_model_name = list(MODELS.keys())[0]
|
| 402 |
load_model(default_model_name)
|
| 403 |
|
| 404 |
# Create interface
|
| 405 |
+
|
| 406 |
+
with gr.Blocks(
|
| 407 |
+
title="Dhivehi TTS Demos",
|
| 408 |
css="""
|
| 409 |
.dhivehi-text textarea {
|
| 410 |
font-size: 18px !important;
|
|
|
|
| 421 |
}
|
| 422 |
"""
|
| 423 |
) as app:
|
| 424 |
+
with gr.Tab("🎙️ CSM Speech Generator"):
|
| 425 |
+
gr.Markdown("# 🎙️ CSM Dhivehi Speech Generator")
|
| 426 |
+
|
| 427 |
+
# Model selection
|
| 428 |
+
with gr.Row():
|
| 429 |
+
model_dropdown = gr.Dropdown(
|
| 430 |
+
choices=list(MODELS.keys()),
|
| 431 |
+
value=list(MODELS.keys())[0],
|
| 432 |
+
label="🤖 Select Model"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
)
|
| 434 |
+
model_info = gr.Textbox(
|
| 435 |
+
value=get_model_info(),
|
| 436 |
+
label="Model Status",
|
| 437 |
+
interactive=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
)
|
| 439 |
|
| 440 |
+
def change_model(model_name):
|
| 441 |
+
success = load_model(model_name)
|
| 442 |
+
if success:
|
| 443 |
+
choices = get_speaker_choices()
|
| 444 |
+
# Generate new speaker display choices for the new model
|
| 445 |
+
current_prompts = get_current_speaker_prompts()
|
| 446 |
+
new_speaker_choices = [(f"{prompt_data['speaker_id']}: {prompt_data['name']}", prompt_data['speaker_id'])
|
| 447 |
+
for prompt_key, prompt_data in current_prompts.items()]
|
| 448 |
+
display_choices = [choice[0] for choice in new_speaker_choices]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
|
| 450 |
+
return (
|
| 451 |
+
gr.update(value=get_model_info()),
|
| 452 |
+
gr.update(choices=choices, value=choices[0]),
|
| 453 |
+
gr.update(choices=choices, value=choices[1] if len(choices) > 1 else choices[0]),
|
| 454 |
+
# Update simple generation speaker radio
|
| 455 |
+
gr.update(choices=display_choices, value=display_choices[0] if display_choices else "0: Speaker"),
|
| 456 |
+
# Update context generation speaker radio
|
| 457 |
+
gr.update(choices=display_choices, value=display_choices[0] if display_choices else "0: Speaker")
|
| 458 |
+
)
|
| 459 |
+
return (
|
| 460 |
+
gr.update(value="Error loading model"),
|
| 461 |
+
gr.update(),
|
| 462 |
+
gr.update(),
|
| 463 |
+
gr.update(),
|
| 464 |
+
gr.update()
|
| 465 |
)
|
| 466 |
|
| 467 |
+
with gr.Tabs():
|
| 468 |
+
# Simple Generation
|
| 469 |
+
with gr.TabItem("🎯 Simple Generation"):
|
| 470 |
+
gr.Markdown("### Generate speech from text without context")
|
| 471 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
with gr.Row():
|
| 473 |
with gr.Column():
|
| 474 |
+
simple_text = gr.Textbox(
|
| 475 |
+
label="Text to Generate (Dhivehi)",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 476 |
placeholder="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
| 477 |
+
value="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
| 478 |
+
lines=3,
|
| 479 |
elem_classes=["dhivehi-text"]
|
| 480 |
)
|
| 481 |
+
# Generate speaker choices from current model's speaker prompts
|
| 482 |
+
current_prompts = get_current_speaker_prompts()
|
| 483 |
+
speaker_choices = [(f"{prompt_data['speaker_id']}: {prompt_data['name']}", prompt_data['speaker_id'])
|
| 484 |
+
for prompt_key, prompt_data in current_prompts.items()]
|
| 485 |
+
simple_speaker = gr.Radio(
|
| 486 |
+
choices=[choice[0] for choice in speaker_choices],
|
| 487 |
+
label="Speaker",
|
| 488 |
+
value=speaker_choices[0][0] if speaker_choices else "0: Speaker"
|
| 489 |
+
)
|
| 490 |
+
simple_btn = gr.Button("🎵 Generate", variant="primary")
|
| 491 |
|
| 492 |
with gr.Column():
|
| 493 |
+
simple_audio = gr.Audio(label="Generated Audio")
|
| 494 |
+
simple_status = gr.Textbox(label="Status", interactive=False)
|
| 495 |
+
|
| 496 |
+
def simple_generate_with_mapping(text, speaker_display):
|
| 497 |
+
# Extract speaker ID from display text (e.g., "0: Female Speaker 01" -> "0")
|
| 498 |
+
speaker_id = speaker_display.split(":")[0]
|
| 499 |
+
return generate_simple_audio(text, speaker_id)
|
| 500 |
+
|
| 501 |
+
simple_btn.click(
|
| 502 |
+
simple_generate_with_mapping,
|
| 503 |
+
inputs=[simple_text, simple_speaker],
|
| 504 |
+
outputs=[simple_audio, simple_status]
|
| 505 |
+
)
|
| 506 |
+
|
| 507 |
+
# Context Generation
|
| 508 |
+
with gr.TabItem("🎭 Context Generation"):
|
| 509 |
+
gr.Markdown("### Generate speech with audio context")
|
| 510 |
+
|
| 511 |
+
with gr.Row():
|
| 512 |
+
with gr.Column():
|
| 513 |
+
context_text = gr.Textbox(
|
| 514 |
+
label="Context Text",
|
| 515 |
+
placeholder="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
| 516 |
+
value="އައިލީޝް އޭނާއަތަށް ލިބުނީ އެންމެ ނުވަ މަހުގަ",
|
| 517 |
lines=2,
|
| 518 |
+
elem_classes=["dhivehi-text"]
|
| 519 |
+
)
|
| 520 |
+
context_audio = gr.Audio(
|
| 521 |
+
label="Context Audio",
|
| 522 |
+
type="filepath"
|
| 523 |
+
)
|
| 524 |
+
target_text = gr.Textbox(
|
| 525 |
+
label="Text to Generate",
|
| 526 |
placeholder="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
| 527 |
+
value="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
| 528 |
+
lines=3,
|
| 529 |
elem_classes=["dhivehi-text"]
|
| 530 |
)
|
| 531 |
+
# Generate speaker choices for context generation
|
| 532 |
+
context_speaker = gr.Radio(
|
| 533 |
+
choices=[choice[0] for choice in speaker_choices],
|
| 534 |
+
label="Speaker",
|
| 535 |
+
value=speaker_choices[0][0] if speaker_choices else "0: Speaker"
|
| 536 |
+
)
|
| 537 |
+
context_btn = gr.Button("🎵 Generate with Context", variant="primary")
|
| 538 |
+
|
| 539 |
+
with gr.Column():
|
| 540 |
+
context_audio_out = gr.Audio(label="Generated Audio")
|
| 541 |
+
context_status = gr.Textbox(label="Status", interactive=False)
|
| 542 |
+
|
| 543 |
+
def context_generate_with_mapping(text, speaker_display, context_text_val, context_audio_val):
|
| 544 |
+
# Extract speaker ID from display text
|
| 545 |
+
speaker_id = speaker_display.split(":")[0]
|
| 546 |
+
return generate_context_audio(text, speaker_id, context_text_val, context_audio_val)
|
| 547 |
+
|
| 548 |
+
context_btn.click(
|
| 549 |
+
context_generate_with_mapping,
|
| 550 |
+
inputs=[target_text, context_speaker, context_text, context_audio],
|
| 551 |
+
outputs=[context_audio_out, context_status]
|
| 552 |
+
)
|
| 553 |
|
| 554 |
+
# Conversation Generation
|
| 555 |
+
with gr.TabItem("💬 Conversation"):
|
| 556 |
+
gr.Markdown("### Generate dual-speaker conversations")
|
| 557 |
+
|
| 558 |
+
with gr.Row():
|
| 559 |
+
speaker_a = gr.Dropdown(
|
| 560 |
+
choices=get_speaker_choices(),
|
| 561 |
+
label="Speaker A",
|
| 562 |
+
value=get_speaker_choices()[0]
|
| 563 |
+
)
|
| 564 |
+
speaker_b = gr.Dropdown(
|
| 565 |
+
choices=get_speaker_choices(),
|
| 566 |
+
label="Speaker B",
|
| 567 |
+
value=get_speaker_choices()[1] if len(get_speaker_choices()) > 1 else get_speaker_choices()[0]
|
| 568 |
+
)
|
| 569 |
+
|
| 570 |
+
with gr.Accordion("🎵 Audio Style References", open=False):
|
| 571 |
+
with gr.Row():
|
| 572 |
+
with gr.Column():
|
| 573 |
+
gr.Markdown("**Speaker A Context**")
|
| 574 |
+
speaker_a_audio = gr.Audio(
|
| 575 |
+
type="filepath",
|
| 576 |
+
label="Speaker A Audio Style"
|
| 577 |
+
)
|
| 578 |
+
speaker_a_text = gr.Textbox(
|
| 579 |
+
label="Speaker A Context Text",
|
| 580 |
+
lines=2,
|
| 581 |
+
placeholder="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
| 582 |
+
elem_classes=["dhivehi-text"]
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
with gr.Column():
|
| 586 |
+
gr.Markdown("**Speaker B Context**")
|
| 587 |
+
speaker_b_audio = gr.Audio(
|
| 588 |
+
type="filepath",
|
| 589 |
+
label="Speaker B Audio Style"
|
| 590 |
+
)
|
| 591 |
+
speaker_b_text = gr.Textbox(
|
| 592 |
+
label="Speaker B Context Text",
|
| 593 |
+
lines=2,
|
| 594 |
+
placeholder="މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ",
|
| 595 |
+
elem_classes=["dhivehi-text"]
|
| 596 |
+
)
|
| 597 |
+
|
| 598 |
+
with gr.Accordion("⚙️ Options", open=False):
|
| 599 |
+
use_style = gr.Checkbox(
|
| 600 |
+
label="Use audio style references",
|
| 601 |
+
value=True
|
| 602 |
+
)
|
| 603 |
+
split_sentences_checkbox = gr.Checkbox(
|
| 604 |
+
label="Split sentences",
|
| 605 |
+
value=False
|
| 606 |
+
)
|
| 607 |
+
|
| 608 |
+
dialogue_text = gr.Textbox(
|
| 609 |
+
lines=6,
|
| 610 |
+
placeholder="ދަރިފުޅު މިއަދު ހާދަ ލަސްތިވީ.. މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ...... ކޮބާ ތިޔަ ރިޕޯޓް ފޮތް؟\nދަބަހުގަ އެބައޮތް!.\nވަދެބަލަ އެތެރެއަށް!... ދީބަލަ ރިޕޯޓްފޮތް މަންމަ ބަލައިލަން!",
|
| 611 |
+
value="ދަރިފުޅު މިއަދު ހާދަ ލަސްތިވީ.. މަންމަ ކިހާއިރެއް ދަރިފުޅުގެ އިންތިޒާރުގަ އިންނަތާ...... ކޮބާ ތިޔަ ރިޕޯޓް ފޮތް؟\nދަބަހުގަ އެބައޮތް!.\nވަދެބަލަ އެތެރެއަށް!... ދީބަލަ ރިޕޯޓްފޮތް މަންމަ ބަލައިލަން!",
|
| 612 |
+
label="Dialogue Lines (one per line)",
|
| 613 |
+
elem_classes=["dhivehi-text"]
|
| 614 |
)
|
| 615 |
+
|
| 616 |
+
conv_btn = gr.Button("🎵 Generate Conversation", variant="primary")
|
| 617 |
+
conv_audio = gr.Audio(label="Generated Conversation")
|
| 618 |
+
conv_status = gr.Textbox(label="Status", interactive=False)
|
| 619 |
+
|
| 620 |
+
conv_btn.click(
|
| 621 |
+
generate_conversation,
|
| 622 |
+
inputs=[speaker_a, speaker_b, speaker_a_audio, speaker_a_text,
|
| 623 |
+
speaker_b_audio, speaker_b_text, dialogue_text,
|
| 624 |
+
split_sentences_checkbox, use_style],
|
| 625 |
+
outputs=[conv_audio, conv_status]
|
| 626 |
)
|
| 627 |
+
|
| 628 |
+
# Wire up model change
|
| 629 |
+
model_dropdown.change(
|
| 630 |
+
change_model,
|
| 631 |
+
inputs=[model_dropdown],
|
| 632 |
+
outputs=[model_info, speaker_a, speaker_b, simple_speaker, context_speaker]
|
| 633 |
+
)
|
| 634 |
+
|
| 635 |
+
gr.Markdown(f"""
|
| 636 |
+
---
|
| 637 |
+
**Current Model:** {get_model_info()}
|
| 638 |
+
|
| 639 |
+
**Tips:**
|
| 640 |
+
- Simple: Basic text-to-speech
|
| 641 |
+
- Context: Use reference audio for voice consistency
|
| 642 |
+
- Conversation: Multi-speaker dialogues with style control
|
| 643 |
+
|
| 644 |
+
**Issues:**
|
| 645 |
+
- Context: Context breaks sometimes. Adding multiple context audio seems to make it work, or adding previous generation to the context helps.
|
| 646 |
+
- Audio: Sometimes the generated audio is not in sync with the text.
|
| 647 |
+
- Long sentences: Generated long sentences seems sped up.
|
| 648 |
+
- Repeating words: Generated text sometimes repeats words.
|
| 649 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 650 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 651 |
if __name__ == "__main__":
|
| 652 |
# Initialize default model on startup
|
| 653 |
initialize_default_model()
|
| 654 |
|
|
|
|
| 655 |
app.launch(share=False)
|