Spaces:
Running
Running
File size: 5,248 Bytes
4832b3b f1b9dc0 4832b3b f1b9dc0 1f9ba91 f1b9dc0 21afc70 f1b9dc0 ea7c4ee 3722864 ea7c4ee e00f1a9 ea7c4ee 3722864 ea7c4ee 3722864 ea7c4ee 3722864 ea7c4ee 3722864 ca83b72 3722864 ca83b72 3722864 ea7c4ee 3722864 ea7c4ee 3722864 ea7c4ee 4832b3b e00f1a9 4832b3b e00f1a9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
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...")
# Fallback 1: Hugging Face Inference API
try:
from huggingface_hub import InferenceClient
from dotenv import load_dotenv
from pathlib import Path
import traceback
# Load env vars
env_path = Path(__file__).parent / '.env'
load_dotenv(dotenv_path=env_path)
hf_token = os.getenv("HF_TOKEN")
if hf_token:
print(f"HF_TOKEN found (starts with): {hf_token[:4]}...")
else:
print("WARNING: HF_TOKEN is MISSING in environment variables!")
client = InferenceClient(token=hf_token)
# List of models to try (in order of preference)
# 1. Facebook MMS (Reliable, standard)
# 2. ESPnet LJSpeech (High quality female voice)
models = ["facebook/mms-tts-eng", "espnet/kan-bayashi_ljspeech_vits"]
for model in models:
try:
print(f"Attempting HF Inference with model: {model}")
# Use direct POST to bypass client-side provider lookup issues
# The API returns raw audio bytes for TTS models
audio_bytes = client.post(json={"inputs": text}, model=model)
print(f"HF Inference successful with {model}, received {len(audio_bytes)} bytes")
fd, path = tempfile.mkstemp(suffix=".flac")
os.close(fd)
with open(path, "wb") as f:
f.write(audio_bytes)
return path
except Exception as model_err:
print(f"HF Model {model} failed: {model_err}")
# traceback.print_exc() # Reduce noise
continue # Try next model
print("All HF models failed. Moving to gTTS...")
raise Exception("All HF models failed")
except Exception as e2:
print(f"HF API Fallback failed completely. 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"},
]
|