Spaces:
Sleeping
Sleeping
| import edge_tts | |
| import tempfile | |
| import os | |
| # Use Microsoft Edge TTS - High quality neural voices | |
| # Includes sexy, hot female voices with various accents | |
| async def generate_audio(text: str, voice: str) -> str: | |
| """ | |
| Generate audio using Microsoft Edge TTS with high-quality neural voices | |
| """ | |
| try: | |
| print(f"Generating audio for voice: {voice}, text length: {len(text)}") | |
| if not text: | |
| raise ValueError("Text is empty") | |
| # Create a temporary file with .mp3 extension | |
| fd, path = tempfile.mkstemp(suffix=".mp3") | |
| os.close(fd) | |
| # Generate speech using edge-tts | |
| communicate = edge_tts.Communicate(text, voice) | |
| await communicate.save(path) | |
| return path | |
| except Exception as e: | |
| print(f"Edge TTS Failed: {e}. Attempting fallback to HF Inference API...") | |
| try: | |
| # Fallback 1: Hugging Face Inference API (Realistic Female Voice) | |
| # using espnet/kan-bayashi_ljspeech_vits (High quality single speaker) | |
| from huggingface_hub import InferenceClient | |
| from dotenv import load_dotenv | |
| from pathlib import Path | |
| # Load env vars if not already loaded | |
| env_path = Path(__file__).parent / '.env' | |
| load_dotenv(dotenv_path=env_path) | |
| hf_token = os.getenv("HF_TOKEN") | |
| client = InferenceClient(token=hf_token) | |
| # Generate audio using HF API | |
| # This model is a high quality female voice | |
| audio_bytes = client.text_to_speech(text, model="espnet/kan-bayashi_ljspeech_vits") | |
| fd, path = tempfile.mkstemp(suffix=".flac") # Model returns flac usually | |
| os.close(fd) | |
| with open(path, "wb") as f: | |
| f.write(audio_bytes) | |
| print("Successfully generated audio using HF Inference API") | |
| return path | |
| except Exception as e2: | |
| print(f"HF API Fallback failed: {e2}. Attempting fallback to gTTS...") | |
| try: | |
| # Fallback 2: gTTS (Google Text-to-Speech) | |
| from gtts import gTTS | |
| fd, path = tempfile.mkstemp(suffix=".mp3") | |
| os.close(fd) | |
| # Use default English voice for fallback | |
| tts = gTTS(text=text, lang='en') | |
| tts.save(path) | |
| print("Successfully generated audio using gTTS fallback") | |
| return path | |
| except Exception as e3: | |
| print(f"gTTS Fallback also failed: {e3}") | |
| import traceback | |
| traceback.print_exc() | |
| raise e | |
| def get_voices(): | |
| """ | |
| Return curated list of sexy, hot female voices | |
| Featuring Microsoft's best neural voices with various styles | |
| """ | |
| return [ | |
| # ๐ฅ HOTTEST FEMALE VOICES - Sexy & Sultry ๐ฅ | |
| {"name": "๐ Aria (Sexy US) - HOTTEST", "id": "en-US-AriaNeural"}, | |
| {"name": "๐ Jenny (Seductive US)", "id": "en-US-JennyNeural"}, | |
| {"name": "โจ Michelle (Flirty US)", "id": "en-US-MichelleNeural"}, | |
| {"name": "๐น Ashley (Sweet US)", "id": "en-US-AshleyNeural"}, | |
| {"name": "๐ Sara (Warm US)", "id": "en-US-SaraNeural"}, | |
| # ๐ฌ๐ง British Accent - Elegant & Sophisticated | |
| {"name": "๐ Sonia (Sexy British)", "id": "en-GB-SoniaNeural"}, | |
| {"name": "๐ Libby (Cute British)", "id": "en-GB-LibbyNeural"}, | |
| {"name": "๐ Mia (Sweet British)", "id": "en-GB-MiaNeural"}, | |
| # ๐ฆ๐บ Australian Accent - Fun & Playful | |
| {"name": "๐ด Natasha (Aussie Babe)", "id": "en-AU-NatashaNeural"}, | |
| {"name": "โ๏ธ Freya (Aussie Darling)", "id": "en-AU-FreyaNeural"}, | |
| # ๐ฎ๐ณ Indian Accent - Exotic & Beautiful | |
| {"name": "๐บ Neerja (Indian Beauty)", "id": "en-IN-NeerjaNeural"}, | |
| # ๐จ๐ฆ Canadian - Friendly & Approachable | |
| {"name": "๐ Clara (Canadian Cutie)", "id": "en-CA-ClaraNeural"}, | |
| # ๐ฎ๐ช Irish Accent - Charming | |
| {"name": "โ๏ธ Emily (Irish Charm)", "id": "en-IE-EmilyNeural"}, | |
| ] |