File size: 5,535 Bytes
4832b3b
 
 
 
f1b9dc0
 
 
4832b3b
f1b9dc0
 
 
 
1f9ba91
 
 
 
f1b9dc0
 
 
 
 
 
 
 
 
21afc70
f1b9dc0
ea7c4ee
3722864
 
ea7c4ee
c08931b
ea7c4ee
 
e00f1a9
ea7c4ee
3722864
ea7c4ee
 
 
 
3722864
 
 
 
 
 
 
 
 
ea7c4ee
c08931b
 
3722864
 
 
c08931b
 
 
 
 
 
 
 
 
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
129
130
131
132
133
134
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:
            import requests
            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!")

            # 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"]
            
            headers = {"Authorization": f"Bearer {hf_token}"}
            
            for model in models:
                try:
                    print(f"Attempting HF Inference with model: {model}")
                    api_url = f"https://api-inference.huggingface.co/models/{model}"
                    
                    # Use direct requests to bypass library version issues
                    response = requests.post(api_url, headers=headers, json={"inputs": text}, timeout=30)
                    
                    if response.status_code != 200:
                        raise Exception(f"API returned status {response.status_code}: {response.text}")
                        
                    audio_bytes = response.content
                    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"},
    ]