Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- README.md +74 -12
- app.py +326 -0
- config.yaml +22 -0
- requirements.txt +10 -0
README.md
CHANGED
|
@@ -1,14 +1,76 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
| 1 |
+
# π€ Long-Form Text-to-Speech Generator
|
| 2 |
+
|
| 3 |
+
A powerful Hugging Face Space that converts text of any length into natural, human-like speech using completely free AI models.
|
| 4 |
+
|
| 5 |
+
## β¨ Features
|
| 6 |
+
|
| 7 |
+
- **π Unlimited Text Length**: Handle texts of any size, from short sentences to entire articles
|
| 8 |
+
- **π€ Human-like Voice**: Uses Microsoft's SpeechT5 model for natural speech synthesis
|
| 9 |
+
- **β‘ Smart Text Processing**: Intelligent chunking preserves sentence flow and natural pauses
|
| 10 |
+
- **π Completely Free**: Uses only open-source models, no API keys required
|
| 11 |
+
- **π§ Auto-preprocessing**: Handles abbreviations, numbers, and text normalization
|
| 12 |
+
- **π± Easy to Use**: Simple web interface built with Gradio
|
| 13 |
+
|
| 14 |
+
## π οΈ How It Works
|
| 15 |
+
|
| 16 |
+
1. **Text Preprocessing**: Cleans and normalizes input text, handling abbreviations and numbers
|
| 17 |
+
2. **Smart Chunking**: Splits long text at natural sentence boundaries (max 500 chars per chunk)
|
| 18 |
+
3. **Speech Generation**: Processes each chunk using SpeechT5 TTS model
|
| 19 |
+
4. **Audio Merging**: Combines all audio segments with natural pauses between chunks
|
| 20 |
+
|
| 21 |
+
## π Models Used
|
| 22 |
+
|
| 23 |
+
- **Text-to-Speech**: `microsoft/speecht5_tts` - High-quality neural TTS
|
| 24 |
+
- **Vocoder**: `microsoft/speecht5_hifigan` - Neural vocoder for audio generation
|
| 25 |
+
- **Speaker Embeddings**: CMU Arctic dataset for consistent voice characteristics
|
| 26 |
+
|
| 27 |
+
## π» Usage
|
| 28 |
+
|
| 29 |
+
1. Enter or paste your text in the input box (no length limit!)
|
| 30 |
+
2. Click "Generate Speech"
|
| 31 |
+
3. Wait for processing (longer texts take more time)
|
| 32 |
+
4. Download or play the generated audio
|
| 33 |
+
|
| 34 |
+
## π Tips for Best Results
|
| 35 |
+
|
| 36 |
+
- Use proper punctuation for natural pauses
|
| 37 |
+
- Well-formatted text produces better speech quality
|
| 38 |
+
- The system automatically handles common abbreviations
|
| 39 |
+
- Numbers are converted to spoken form
|
| 40 |
+
|
| 41 |
+
## π§ Technical Details
|
| 42 |
+
|
| 43 |
+
- **Architecture**: Transformer-based neural TTS
|
| 44 |
+
- **Sample Rate**: 16 kHz
|
| 45 |
+
- **Audio Format**: WAV
|
| 46 |
+
- **Processing**: CPU-optimized (works on free Hugging Face hardware)
|
| 47 |
+
- **Memory Efficient**: Processes text in chunks to handle large documents
|
| 48 |
+
|
| 49 |
+
## π Local Installation
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
git clone <your-space-url>
|
| 53 |
+
cd <your-space-name>
|
| 54 |
+
pip install -r requirements.txt
|
| 55 |
+
python app.py
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
## π License
|
| 59 |
+
|
| 60 |
+
This project uses open-source models and is available for free use. Please check individual model licenses:
|
| 61 |
+
- SpeechT5: Microsoft Research License
|
| 62 |
+
- CMU Arctic: Academic/Research License
|
| 63 |
+
|
| 64 |
+
## π€ Contributing
|
| 65 |
+
|
| 66 |
+
Feel free to submit issues and enhancement requests!
|
| 67 |
+
|
| 68 |
+
## π Links
|
| 69 |
+
|
| 70 |
+
- [SpeechT5 Paper](https://arxiv.org/abs/2110.07205)
|
| 71 |
+
- [Hugging Face Transformers](https://huggingface.co/transformers/)
|
| 72 |
+
- [Gradio Documentation](https://gradio.app/docs/)
|
| 73 |
+
|
| 74 |
---
|
| 75 |
|
| 76 |
+
**Built with β€οΈ using Hugging Face Transformers and Gradio**
|
app.py
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import numpy as np
|
| 4 |
+
import re
|
| 5 |
+
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
| 6 |
+
from datasets import load_dataset
|
| 7 |
+
import soundfile as sf
|
| 8 |
+
import io
|
| 9 |
+
import tempfile
|
| 10 |
+
import os
|
| 11 |
+
from pydub import AudioSegment
|
| 12 |
+
from pydub.silence import split_on_silence
|
| 13 |
+
import nltk
|
| 14 |
+
from nltk.tokenize import sent_tokenize
|
| 15 |
+
import warnings
|
| 16 |
+
warnings.filterwarnings("ignore")
|
| 17 |
+
|
| 18 |
+
# Download required NLTK data
|
| 19 |
+
try:
|
| 20 |
+
nltk.data.find('tokenizers/punkt')
|
| 21 |
+
except LookupError:
|
| 22 |
+
nltk.download('punkt')
|
| 23 |
+
|
| 24 |
+
class LongFormTTS:
|
| 25 |
+
def __init__(self):
|
| 26 |
+
print("Loading TTS models...")
|
| 27 |
+
|
| 28 |
+
# Load SpeechT5 models (free and high quality)
|
| 29 |
+
self.processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
| 30 |
+
self.model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
|
| 31 |
+
self.vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
| 32 |
+
|
| 33 |
+
# Load speaker embeddings dataset
|
| 34 |
+
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
| 35 |
+
self.speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
| 36 |
+
|
| 37 |
+
print("Models loaded successfully!")
|
| 38 |
+
|
| 39 |
+
def preprocess_text(self, text):
|
| 40 |
+
"""Clean and prepare text for TTS"""
|
| 41 |
+
# Remove extra whitespace
|
| 42 |
+
text = re.sub(r'\s+', ' ', text.strip())
|
| 43 |
+
|
| 44 |
+
# Handle common abbreviations
|
| 45 |
+
abbreviations = {
|
| 46 |
+
'Dr.': 'Doctor',
|
| 47 |
+
'Mr.': 'Mister',
|
| 48 |
+
'Mrs.': 'Missus',
|
| 49 |
+
'Ms.': 'Miss',
|
| 50 |
+
'Prof.': 'Professor',
|
| 51 |
+
'etc.': 'etcetera',
|
| 52 |
+
'vs.': 'versus',
|
| 53 |
+
'e.g.': 'for example',
|
| 54 |
+
'i.e.': 'that is',
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
for abbr, full in abbreviations.items():
|
| 58 |
+
text = text.replace(abbr, full)
|
| 59 |
+
|
| 60 |
+
# Handle numbers (basic)
|
| 61 |
+
text = re.sub(r'\b(\d+)\b', lambda m: self.number_to_words(int(m.group())), text)
|
| 62 |
+
|
| 63 |
+
return text
|
| 64 |
+
|
| 65 |
+
def number_to_words(self, num):
|
| 66 |
+
"""Convert numbers to words (basic implementation)"""
|
| 67 |
+
if num == 0:
|
| 68 |
+
return "zero"
|
| 69 |
+
|
| 70 |
+
ones = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
| 71 |
+
teens = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
|
| 72 |
+
"sixteen", "seventeen", "eighteen", "nineteen"]
|
| 73 |
+
tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
|
| 74 |
+
|
| 75 |
+
if num < 10:
|
| 76 |
+
return ones[num]
|
| 77 |
+
elif num < 20:
|
| 78 |
+
return teens[num - 10]
|
| 79 |
+
elif num < 100:
|
| 80 |
+
return tens[num // 10] + ("" if num % 10 == 0 else " " + ones[num % 10])
|
| 81 |
+
elif num < 1000:
|
| 82 |
+
return ones[num // 100] + " hundred" + ("" if num % 100 == 0 else " " + self.number_to_words(num % 100))
|
| 83 |
+
else:
|
| 84 |
+
return str(num) # Fallback for larger numbers
|
| 85 |
+
|
| 86 |
+
def chunk_text(self, text, max_length=500):
|
| 87 |
+
"""Split text into manageable chunks while preserving sentence boundaries"""
|
| 88 |
+
sentences = sent_tokenize(text)
|
| 89 |
+
chunks = []
|
| 90 |
+
current_chunk = ""
|
| 91 |
+
|
| 92 |
+
for sentence in sentences:
|
| 93 |
+
# If single sentence is too long, split by clauses
|
| 94 |
+
if len(sentence) > max_length:
|
| 95 |
+
clauses = re.split(r'[,;:]', sentence)
|
| 96 |
+
for clause in clauses:
|
| 97 |
+
clause = clause.strip()
|
| 98 |
+
if len(current_chunk + clause) > max_length:
|
| 99 |
+
if current_chunk:
|
| 100 |
+
chunks.append(current_chunk.strip())
|
| 101 |
+
current_chunk = clause
|
| 102 |
+
else:
|
| 103 |
+
# Even single clause is too long, force split
|
| 104 |
+
words = clause.split()
|
| 105 |
+
temp_chunk = ""
|
| 106 |
+
for word in words:
|
| 107 |
+
if len(temp_chunk + word) > max_length:
|
| 108 |
+
if temp_chunk:
|
| 109 |
+
chunks.append(temp_chunk.strip())
|
| 110 |
+
temp_chunk = word
|
| 111 |
+
else:
|
| 112 |
+
chunks.append(word) # Single word longer than limit
|
| 113 |
+
else:
|
| 114 |
+
temp_chunk += " " + word if temp_chunk else word
|
| 115 |
+
if temp_chunk:
|
| 116 |
+
current_chunk = temp_chunk
|
| 117 |
+
else:
|
| 118 |
+
current_chunk += " " + clause if current_chunk else clause
|
| 119 |
+
else:
|
| 120 |
+
if len(current_chunk + sentence) > max_length:
|
| 121 |
+
if current_chunk:
|
| 122 |
+
chunks.append(current_chunk.strip())
|
| 123 |
+
current_chunk = sentence
|
| 124 |
+
else:
|
| 125 |
+
chunks.append(sentence)
|
| 126 |
+
else:
|
| 127 |
+
current_chunk += " " + sentence if current_chunk else sentence
|
| 128 |
+
|
| 129 |
+
if current_chunk:
|
| 130 |
+
chunks.append(current_chunk.strip())
|
| 131 |
+
|
| 132 |
+
return [chunk for chunk in chunks if chunk.strip()]
|
| 133 |
+
|
| 134 |
+
def generate_speech_chunk(self, text_chunk):
|
| 135 |
+
"""Generate speech for a single text chunk"""
|
| 136 |
+
try:
|
| 137 |
+
inputs = self.processor(text=text_chunk, return_tensors="pt")
|
| 138 |
+
speech = self.model.generate_speech(
|
| 139 |
+
inputs["input_ids"],
|
| 140 |
+
self.speaker_embeddings,
|
| 141 |
+
vocoder=self.vocoder
|
| 142 |
+
)
|
| 143 |
+
return speech.numpy()
|
| 144 |
+
except Exception as e:
|
| 145 |
+
print(f"Error generating speech for chunk: {e}")
|
| 146 |
+
return np.array([])
|
| 147 |
+
|
| 148 |
+
def generate_long_speech(self, text, progress_callback=None):
|
| 149 |
+
"""Generate speech for long text by processing in chunks"""
|
| 150 |
+
# Preprocess text
|
| 151 |
+
text = self.preprocess_text(text)
|
| 152 |
+
|
| 153 |
+
# Split into chunks
|
| 154 |
+
chunks = self.chunk_text(text)
|
| 155 |
+
print(f"Split text into {len(chunks)} chunks")
|
| 156 |
+
|
| 157 |
+
if not chunks:
|
| 158 |
+
return np.array([]), 16000
|
| 159 |
+
|
| 160 |
+
# Generate speech for each chunk
|
| 161 |
+
audio_segments = []
|
| 162 |
+
total_chunks = len(chunks)
|
| 163 |
+
|
| 164 |
+
for i, chunk in enumerate(chunks):
|
| 165 |
+
if progress_callback:
|
| 166 |
+
progress_callback(f"Processing chunk {i+1}/{total_chunks}: {chunk[:50]}...")
|
| 167 |
+
|
| 168 |
+
speech_chunk = self.generate_speech_chunk(chunk)
|
| 169 |
+
if len(speech_chunk) > 0:
|
| 170 |
+
audio_segments.append(speech_chunk)
|
| 171 |
+
|
| 172 |
+
# Add small pause between chunks (200ms of silence)
|
| 173 |
+
pause_duration = int(0.2 * 16000) # 200ms at 16kHz
|
| 174 |
+
silence = np.zeros(pause_duration)
|
| 175 |
+
audio_segments.append(silence)
|
| 176 |
+
|
| 177 |
+
if not audio_segments:
|
| 178 |
+
return np.array([]), 16000
|
| 179 |
+
|
| 180 |
+
# Concatenate all audio segments
|
| 181 |
+
final_audio = np.concatenate(audio_segments)
|
| 182 |
+
|
| 183 |
+
return final_audio, 16000
|
| 184 |
+
|
| 185 |
+
# Initialize TTS system
|
| 186 |
+
tts_system = LongFormTTS()
|
| 187 |
+
|
| 188 |
+
def text_to_speech_interface(text, progress=gr.Progress()):
|
| 189 |
+
"""Main interface function for Gradio"""
|
| 190 |
+
if not text.strip():
|
| 191 |
+
return None, "Please enter some text to convert to speech."
|
| 192 |
+
|
| 193 |
+
def progress_callback(message):
|
| 194 |
+
progress(0.5, desc=message)
|
| 195 |
+
|
| 196 |
+
try:
|
| 197 |
+
progress(0.1, desc="Starting text-to-speech conversion...")
|
| 198 |
+
|
| 199 |
+
audio, sample_rate = tts_system.generate_long_speech(text, progress_callback)
|
| 200 |
+
|
| 201 |
+
if len(audio) == 0:
|
| 202 |
+
return None, "Failed to generate audio. Please try again."
|
| 203 |
+
|
| 204 |
+
progress(0.9, desc="Finalizing audio...")
|
| 205 |
+
|
| 206 |
+
# Save to temporary file
|
| 207 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
| 208 |
+
sf.write(tmp_file.name, audio, sample_rate)
|
| 209 |
+
audio_path = tmp_file.name
|
| 210 |
+
|
| 211 |
+
progress(1.0, desc="Complete!")
|
| 212 |
+
|
| 213 |
+
return audio_path, f"β
Successfully generated {len(audio)/sample_rate:.1f} seconds of audio!"
|
| 214 |
+
|
| 215 |
+
except Exception as e:
|
| 216 |
+
error_msg = f"β Error: {str(e)}"
|
| 217 |
+
print(error_msg)
|
| 218 |
+
return None, error_msg
|
| 219 |
+
|
| 220 |
+
# Create Gradio interface
|
| 221 |
+
def create_interface():
|
| 222 |
+
with gr.Blocks(
|
| 223 |
+
title="π€ Long-Form Text-to-Speech Generator",
|
| 224 |
+
theme=gr.themes.Soft(),
|
| 225 |
+
css="""
|
| 226 |
+
.main-header {
|
| 227 |
+
text-align: center;
|
| 228 |
+
margin-bottom: 2rem;
|
| 229 |
+
}
|
| 230 |
+
.feature-box {
|
| 231 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 232 |
+
color: white;
|
| 233 |
+
padding: 1rem;
|
| 234 |
+
border-radius: 10px;
|
| 235 |
+
margin: 1rem 0;
|
| 236 |
+
}
|
| 237 |
+
"""
|
| 238 |
+
) as demo:
|
| 239 |
+
|
| 240 |
+
gr.HTML("""
|
| 241 |
+
<div class="main-header">
|
| 242 |
+
<h1>π€ Long-Form Text-to-Speech Generator</h1>
|
| 243 |
+
<p>Convert any length of text to natural human-like speech using free AI models</p>
|
| 244 |
+
</div>
|
| 245 |
+
""")
|
| 246 |
+
|
| 247 |
+
with gr.Row():
|
| 248 |
+
with gr.Column(scale=2):
|
| 249 |
+
text_input = gr.Textbox(
|
| 250 |
+
label="π Enter your text",
|
| 251 |
+
placeholder="Type or paste any text here... No length limit!",
|
| 252 |
+
lines=10,
|
| 253 |
+
max_lines=20
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
generate_btn = gr.Button(
|
| 257 |
+
"π― Generate Speech",
|
| 258 |
+
variant="primary",
|
| 259 |
+
size="lg"
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
with gr.Column(scale=1):
|
| 263 |
+
gr.HTML("""
|
| 264 |
+
<div class="feature-box">
|
| 265 |
+
<h3>β¨ Features</h3>
|
| 266 |
+
<ul>
|
| 267 |
+
<li>π Unlimited text length</li>
|
| 268 |
+
<li>π€ Human-like voice quality</li>
|
| 269 |
+
<li>β‘ Smart text chunking</li>
|
| 270 |
+
<li>π Completely free to use</li>
|
| 271 |
+
<li>π§ Automatic text preprocessing</li>
|
| 272 |
+
</ul>
|
| 273 |
+
</div>
|
| 274 |
+
""")
|
| 275 |
+
|
| 276 |
+
status_text = gr.Textbox(
|
| 277 |
+
label="π Status",
|
| 278 |
+
interactive=False,
|
| 279 |
+
value="Ready to generate speech!"
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
audio_output = gr.Audio(
|
| 283 |
+
label="π Generated Speech",
|
| 284 |
+
type="filepath"
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
# Event handlers
|
| 288 |
+
generate_btn.click(
|
| 289 |
+
fn=text_to_speech_interface,
|
| 290 |
+
inputs=[text_input],
|
| 291 |
+
outputs=[audio_output, status_text]
|
| 292 |
+
)
|
| 293 |
+
|
| 294 |
+
# Example texts
|
| 295 |
+
gr.Examples(
|
| 296 |
+
examples=[
|
| 297 |
+
["Hello! This is a test of the long-form text-to-speech system. It can handle texts of any length by intelligently splitting them into smaller chunks while maintaining natural flow and pronunciation."],
|
| 298 |
+
["The quick brown fox jumps over the lazy dog. This sentence contains every letter of the alphabet and is commonly used for testing text-to-speech systems."],
|
| 299 |
+
["In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to eat: it was a hobbit-hole, and that means comfort."]
|
| 300 |
+
],
|
| 301 |
+
inputs=[text_input]
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
+
gr.HTML("""
|
| 305 |
+
<div style="margin-top: 2rem; padding: 1rem; background: #f0f0f0; border-radius: 5px;">
|
| 306 |
+
<h4>π§ How it works:</h4>
|
| 307 |
+
<ol>
|
| 308 |
+
<li><strong>Text Preprocessing:</strong> Cleans and normalizes your input text</li>
|
| 309 |
+
<li><strong>Smart Chunking:</strong> Splits long text at sentence boundaries</li>
|
| 310 |
+
<li><strong>Speech Generation:</strong> Uses Microsoft's SpeechT5 model for each chunk</li>
|
| 311 |
+
<li><strong>Audio Merging:</strong> Combines all chunks with natural pauses</li>
|
| 312 |
+
</ol>
|
| 313 |
+
<p><em>π‘ Tip: The system works best with well-formatted text with proper punctuation!</em></p>
|
| 314 |
+
</div>
|
| 315 |
+
""")
|
| 316 |
+
|
| 317 |
+
return demo
|
| 318 |
+
|
| 319 |
+
# Launch the app
|
| 320 |
+
if __name__ == "__main__":
|
| 321 |
+
demo = create_interface()
|
| 322 |
+
demo.launch(
|
| 323 |
+
server_name="0.0.0.0",
|
| 324 |
+
server_port=7860,
|
| 325 |
+
share=True
|
| 326 |
+
)
|
config.yaml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
title: Long-Form Text-to-Speech Generator
|
| 2 |
+
emoji: π€
|
| 3 |
+
colorFrom: blue
|
| 4 |
+
colorTo: purple
|
| 5 |
+
sdk: gradio
|
| 6 |
+
sdk_version: 4.0.0
|
| 7 |
+
app_file: app.py
|
| 8 |
+
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
+
short_description: Convert unlimited text to human-like speech using free AI models
|
| 11 |
+
tags:
|
| 12 |
+
- text-to-speech
|
| 13 |
+
- TTS
|
| 14 |
+
- speech-synthesis
|
| 15 |
+
- audio
|
| 16 |
+
- transformers
|
| 17 |
+
- speecht5
|
| 18 |
+
models:
|
| 19 |
+
- microsoft/speecht5_tts
|
| 20 |
+
- microsoft/speecht5_hifigan
|
| 21 |
+
datasets:
|
| 22 |
+
- Matthijs/cmu-arctic-xvectors
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|
| 2 |
+
torch>=2.0.0
|
| 3 |
+
transformers>=4.30.0
|
| 4 |
+
datasets>=2.10.0
|
| 5 |
+
soundfile>=0.12.1
|
| 6 |
+
pydub>=0.25.1
|
| 7 |
+
nltk>=3.8
|
| 8 |
+
numpy>=1.21.0
|
| 9 |
+
scipy>=1.9.0
|
| 10 |
+
librosa>=0.10.0
|