Spaces:
Sleeping
Sleeping
Update app.py
Browse files33 unmodified lines3435363738373839404112 unmodified lines5455565757585997 unmodified lines15715815916116016116216346 unmodified lines2102112122142132142152162172192202182192202212226 unmodified lines2292302312322332342354 unmodified lines2402412422432432442452465 unmodified lines25225325425525625725525625725825926033 unmodified linesclass LongFormTTS: def __init__(self): self.tts = tts self.speakers = speakers # Store available speakers self.sample_rate = 22050 # Coqui default sample rate self.speakers = speakers or ["p225", "p226", "p227", "p228"] # fallback static list self.sample_rate = 22050 # Default sample rate for Coqui TTS
def preprocess_text(self, text): """Clean and prepare text for TTS"""12 unmodified lines text = re.sub(r'\b(\d{1,4})\b', lambda m: self.number_to_words(int(m.group())), text) text = re.sub(r'\b(1[0-9]{3}|20[0-9]{2}|2100)\b', lambda m: m.group(), text) text = re.sub(r'[^\w\s\.,!?;:\-\(\)\'"]', ' ', text) text = re.sub(r'\s+', ' ', text) return text.strip()
def number_to_words(self, num):97 unmodified lines if audio is None: return None, "β Failed to generate audio." progress(0.9, desc="πΎ Saving audio file...") with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file: with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file: sf.write(tmp_file.name, audio, sample_rate) audio_path = tmp_file.name progress(1.0, desc="β
Complete!")46 unmodified lines placeholder="Type or paste your text here... (Max 50,000 characters)", lines=10, max_lines=20, info="Supports any length text with automatic chunking for optimal quality" info="Supports any length text with automatic chunking" ) char_count = gr.HTML("<span style='color: #666;'>Character count: 0 / 50,000</span>") speaker_dropdown = gr.Dropdown( choices=tts_system.speakers if tts_system else [], value=tts_system.speakers[0] if tts_system else None, label="π£οΈ Choose Voice" value=tts_system.speakers[0] if tts_system and tts_system.speakers else None, label="π£οΈ Select Voice" ) generate_btn = gr.Button("π― Generate Speech", variant="primary", size="lg", scale=1) with gr.Column(scale=1):6 unmodified lines <li>β‘ Smart text processing</li> <li>π§ Auto chunking</li> <li>π΅ Natural-sounding speech</li> <li>π MP3 audio output</li> </ul> </div> """)4 unmodified lines count = len(text) if text else 0 color = "#28a745" if count <= 50000 else "#dc3545" return f'<span style="color: {color};">Character count: {count:,} / 50,000</span>'
text_input.change(fn=update_char_count, inputs=[text_input], outputs=[char_count])
generate_btn.click(5 unmodified lines
gr.Examples( examples=[ ["Hello! Welcome to our advanced text-to-speech system. This technology can convert any written text into natural-sounding human speech.", "p225"], ["The quick brown fox jumps over the lazy dog. This pangram contains every letter of the English alphabet and is perfect for testing speech synthesis.", "p226"], ["Artificial intelligence has revolutionized many aspects of our daily lives.", "p227"], ["Hello! Welcome to our advanced text-to-speech system.", "p225"], ["The quick brown fox jumps over the lazy dog.", "p226"], ["Artificial intelligence has revolutionized many aspects of our lives.", "p227"], ], inputs=[text_input, speaker_dropdown], label="π Try These Examples"app.py+11-11