Spaces:
Sleeping
Sleeping
Fix build: replace KittenTTS with edge-tts, pin Python 3.12, add packages.txt for imagemagick
Browse filesFiles changed (4)
- README.md+2-1
- packages.txtAdded+2
- requirements.txt+3-2
- src/classes/Tts.py+71-7
4 unmodified lines56789105 unmodified lines161718192021224 unmodified linescolorTo: purplesdk: gradiosdk_version: "4.44.1"app_file: app.pypinned: false---5 unmodified lines1. **Topic Generation** β LLM generates a video topic from your niche2. **Script Writing** β LLM writes a short video script3. **Image Generation** β Gemini API creates visuals from AI prompts4. **Text-to-Speech** β KittenTTS converts script to natural speech5. **Subtitle Generation** β faster-whisper creates synced subtitles6. **Video Assembly** β MoviePy combines everything into a downloadable MP44 unmodified lines5678910115 unmodified lines171819202122234 unmodified linescolorTo: purplesdk: gradiosdk_version: "4.44.1"python_version: "3.12"app_file: app.pypinned: false---5 unmodified lines1. **Topic Generation** β LLM generates a video topic from your niche2. **Script Writing** β LLM writes a short video script3. **Image Generation** β Gemini API creates visuals from AI prompts4. **Text-to-Speech** β Edge TTS converts script to natural speech5. **Subtitle Generation** β faster-whisper creates synced subtitles6. **Video Assembly** β MoviePy combines everything into a downloadable MP4
12imagemagickffmpeg1 unmodified line23456789101 unmodified linehuggingface_hub>=0.20.0termcolorrequestskittentts @ https://github.com/KittenML/KittenTTS/releases/download/0.8.1/kittentts-0.8.1-py3-none-any.whlsoundfilemoviepyPillow>=10.0.0faster-whispersrt_equalizer1 unmodified line2345678910111 unmodified linehuggingface_hub>=0.20.0termcolorrequestsedge-ttspydubsoundfilemoviepy<2Pillow>=10.0.0faster-whispersrt_equalizer
123456789101112131415161718import osimport soundfile as sffrom kittentts import KittenTTS as KittenModelfrom config import ROOT_DIR, get_tts_voiceKITTEN_MODEL = "KittenML/kitten-tts-mini-0.8"KITTEN_SAMPLE_RATE = 24000class TTS:def __init__(self) -> None:self._model = KittenModel(KITTEN_MODEL)self._voice = get_tts_voice()def synthesize(self, text, output_file=os.path.join(ROOT_DIR, ".mp", "audio.wav")):audio = self._model.generate(text, voice=self._voice)sf.write(output_file, audio, KITTEN_SAMPLE_RATE)return output_file12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182import osfrom config import ROOT_DIR, get_tts_voice, is_running_in_spaces# Voice mapping: friendly name -> edge-tts voice IDEDGE_TTS_VOICES = {"Jasper": "en-US-GuyNeural","Bella": "en-US-JennyNeural","Luna": "en-GB-SoniaNeural","Bruno": "en-US-ChristopherNeural","Rosie": "en-AU-NatashaNeural","Hugo": "en-GB-RyanNeural","Kiki": "en-US-AriaNeural","Leo": "en-US-DavisNeural",}def _use_edge_tts() -> bool:"""Use edge-tts when KittenTTS is not available (e.g. on HF Spaces)."""if is_running_in_spaces():return Truetry:from kittentts import KittenTTS # noqa: F401return Falseexcept ImportError:return Trueclass TTS:def __init__(self) -> None:self._voice = get_tts_voice()self._use_edge = _use_edge_tts()if not self._use_edge:import soundfile # noqa: F401 β ensure availablefrom kittentts import KittenTTS as KittenModelself._model = KittenModel("KittenML/kitten-tts-mini-0.8")self._sample_rate = 24000else:self._model = Nonedef synthesize(self, text, output_file=os.path.join(ROOT_DIR, ".mp", "audio.wav")):if self._use_edge:return self._synthesize_edge(text, output_file)return self._synthesize_kitten(text, output_file)def _synthesize_kitten(self, text, output_file):import soundfile as sfaudio = self._model.generate(text, voice=self._voice)sf.write(output_file, audio, self._sample_rate)return output_filedef _synthesize_edge(self, text, output_file):import asyncioimport edge_ttsvoice_id = EDGE_TTS_VOICES.get(self._voice, "en-US-GuyNeural")# edge-tts outputs mp3; we write to mp3 then keep as-is# MoviePy can handle mp3 audio via ffmpegmp3_path = output_file.rsplit(".", 1)[0] + ".mp3"async def _generate():communicate = edge_tts.Communicate(text, voice_id)await communicate.save(mp3_path)asyncio.run(_generate())# Convert mp3 to wav for compatibility with the rest of the pipelinetry:from pydub import AudioSegmentaudio = AudioSegment.from_mp3(mp3_path)audio.export(output_file, format="wav")os.remove(mp3_path)except ImportError:# If pydub not available, just use the mp3 directly# Rename mp3 to the expected output pathif os.path.exists(output_file):os.remove(output_file)os.rename(mp3_path, output_file)return output_file
README.md+2-1
packages.txtAdded+2
requirements.txt+3-2
src/classes/Tts.py+71-7