Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -611,16 +611,10 @@ class StreamingTTS:
|
|
611 |
return self.output_file
|
612 |
return None
|
613 |
|
614 |
-
def stop(self):
|
615 |
-
"""Stop generation"""
|
616 |
-
self.should_stop = True
|
617 |
-
print("Stop request received")
|
618 |
-
|
619 |
# Load reference example (Malayalam)
|
620 |
EXAMPLES = [{
|
621 |
"audio_url": "https://raw.githubusercontent.com/Aparna0112/voicerecording-_TTS/main/KC%20Voice.wav",
|
622 |
"ref_text": "ഹലോ ഇത് അപരനെ അല്ലേ ഞാൻ ജഗദീപ് ആണ് വിളിക്കുന്നത് ഇപ്പോൾ ഫ്രീയാണോ സംസാരിക്കാമോ ",
|
623 |
-
"synth_text": "ഞാൻ മലയാളം സംസാരിക്കാൻ കഴിയുന്നു."
|
624 |
}]
|
625 |
|
626 |
print("\nPreloading reference audio...")
|
@@ -634,33 +628,20 @@ if ref_audio is None:
|
|
634 |
# Initialize streaming TTS
|
635 |
streaming_tts = StreamingTTS()
|
636 |
|
637 |
-
#
|
638 |
-
def stop_generation():
|
639 |
-
streaming_tts.stop()
|
640 |
-
return "Generation stopped"
|
641 |
-
|
642 |
-
# Gradio interface with offline mode
|
643 |
with gr.Blocks() as iface:
|
644 |
gr.Markdown("## 🚀 IndicF5 Malayalam TTS")
|
645 |
|
646 |
-
with gr.Row():
|
647 |
-
gr.Markdown("### System Status:")
|
648 |
-
system_status = gr.Markdown(f"- Device: {device}\n- Model loaded: {'Yes' if model is not None else 'No'}\n- Reference audio: {'Loaded' if ref_audio is not None else 'Not loaded'}")
|
649 |
-
|
650 |
with gr.Row():
|
651 |
text_input = gr.Textbox(
|
652 |
-
label="Malayalam Text",
|
653 |
placeholder="Enter text here...",
|
654 |
lines=3,
|
655 |
-
value=
|
656 |
)
|
657 |
|
658 |
with gr.Row():
|
659 |
generate_btn = gr.Button("🎤 Generate Speech", variant="primary")
|
660 |
-
stop_btn = gr.Button("🛑 Stop Generation", variant="secondary")
|
661 |
-
|
662 |
-
# Status indicator
|
663 |
-
status_text = gr.Textbox(label="Status", value="Ready", interactive=False)
|
664 |
|
665 |
# Audio output
|
666 |
output_audio = gr.Audio(
|
@@ -669,52 +650,40 @@ with gr.Blocks() as iface:
|
|
669 |
autoplay=True
|
670 |
)
|
671 |
|
672 |
-
# Debug information (hidden by default)
|
673 |
-
with gr.Accordion("Advanced", open=False):
|
674 |
-
debug_output = gr.Textbox(label="Debug Log", value="", lines=5)
|
675 |
-
|
676 |
def start_generation(text):
|
677 |
if not text.strip():
|
678 |
-
return None
|
679 |
-
|
680 |
if model is None:
|
681 |
-
return None
|
682 |
-
|
683 |
if ref_audio is None:
|
684 |
-
return None
|
685 |
|
686 |
# Print the text being processed
|
687 |
print(f"🔍 User input text: '{text}'")
|
688 |
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
ref_sr=ref_sr,
|
700 |
-
ref_text=EXAMPLES[0]["ref_text"] if EXAMPLES else ""
|
701 |
-
)
|
702 |
-
except Exception as e:
|
703 |
-
print(f"Error starting generation: {e}")
|
704 |
-
|
705 |
-
debug_log = f.getvalue()
|
706 |
|
707 |
# Add a delay to ensure file is created
|
708 |
time.sleep(2.0)
|
709 |
|
710 |
audio_path = streaming_tts.get_current_audio()
|
711 |
if audio_path and os.path.exists(audio_path) and os.path.getsize(audio_path) > 0:
|
712 |
-
return audio_path
|
713 |
else:
|
714 |
-
return None
|
715 |
|
716 |
-
generate_btn.click(start_generation, inputs=text_input, outputs=
|
717 |
-
stop_btn.click(stop_generation, inputs=None, outputs=status_text)
|
718 |
|
719 |
# Cleanup on exit
|
720 |
def exit_handler():
|
|
|
611 |
return self.output_file
|
612 |
return None
|
613 |
|
|
|
|
|
|
|
|
|
|
|
614 |
# Load reference example (Malayalam)
|
615 |
EXAMPLES = [{
|
616 |
"audio_url": "https://raw.githubusercontent.com/Aparna0112/voicerecording-_TTS/main/KC%20Voice.wav",
|
617 |
"ref_text": "ഹലോ ഇത് അപരനെ അല്ലേ ഞാൻ ജഗദീപ് ആണ് വിളിക്കുന്നത് ഇപ്പോൾ ഫ്രീയാണോ സംസാരിക്കാമോ ",
|
|
|
618 |
}]
|
619 |
|
620 |
print("\nPreloading reference audio...")
|
|
|
628 |
# Initialize streaming TTS
|
629 |
streaming_tts = StreamingTTS()
|
630 |
|
631 |
+
# Gradio interface with simplified UI
|
|
|
|
|
|
|
|
|
|
|
632 |
with gr.Blocks() as iface:
|
633 |
gr.Markdown("## 🚀 IndicF5 Malayalam TTS")
|
634 |
|
|
|
|
|
|
|
|
|
635 |
with gr.Row():
|
636 |
text_input = gr.Textbox(
|
637 |
+
label="Enter Malayalam Text",
|
638 |
placeholder="Enter text here...",
|
639 |
lines=3,
|
640 |
+
value="" # Start with empty field
|
641 |
)
|
642 |
|
643 |
with gr.Row():
|
644 |
generate_btn = gr.Button("🎤 Generate Speech", variant="primary")
|
|
|
|
|
|
|
|
|
645 |
|
646 |
# Audio output
|
647 |
output_audio = gr.Audio(
|
|
|
650 |
autoplay=True
|
651 |
)
|
652 |
|
|
|
|
|
|
|
|
|
653 |
def start_generation(text):
|
654 |
if not text.strip():
|
655 |
+
return None
|
656 |
+
|
657 |
if model is None:
|
658 |
+
return None
|
659 |
+
|
660 |
if ref_audio is None:
|
661 |
+
return None
|
662 |
|
663 |
# Print the text being processed
|
664 |
print(f"🔍 User input text: '{text}'")
|
665 |
|
666 |
+
try:
|
667 |
+
# Generate speech for the new text
|
668 |
+
streaming_tts.generate(
|
669 |
+
text=text,
|
670 |
+
ref_audio=ref_audio,
|
671 |
+
ref_sr=ref_sr,
|
672 |
+
ref_text=EXAMPLES[0]["ref_text"] if EXAMPLES else ""
|
673 |
+
)
|
674 |
+
except Exception as e:
|
675 |
+
print(f"Error starting generation: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
676 |
|
677 |
# Add a delay to ensure file is created
|
678 |
time.sleep(2.0)
|
679 |
|
680 |
audio_path = streaming_tts.get_current_audio()
|
681 |
if audio_path and os.path.exists(audio_path) and os.path.getsize(audio_path) > 0:
|
682 |
+
return audio_path
|
683 |
else:
|
684 |
+
return None
|
685 |
|
686 |
+
generate_btn.click(start_generation, inputs=text_input, outputs=output_audio)
|
|
|
687 |
|
688 |
# Cleanup on exit
|
689 |
def exit_handler():
|