Spaces:
Sleeping

axeronis commited on
Commit
c5a37fa
·
1 Parent(s): 2bfd3b5

feat(voice): add voice-specific exaggeration and cfg_weight for better quality

Browse files
Files changed (1) hide show
  1. chatterbox-service/server.py +22 -8
chatterbox-service/server.py CHANGED
@@ -22,22 +22,28 @@ app = FastAPI(
22
  version="1.1.0"
23
  )
24
 
25
- # Built-in voices (multilingual)
26
  BUILTIN_VOICES = {
27
  "professional_male": {
28
  "name": "Professional (Male)",
29
  "description": "Confident business voice, works well in Russian/English",
30
- "reference_path": "voices/professional_male.wav"
 
 
31
  },
32
  "friendly_male": {
33
  "name": "Friendly (Male)",
34
  "description": "Warm, approachable voice for building rapport",
35
- "reference_path": "voices/friendly_male.wav"
 
 
36
  },
37
  "professional_female": {
38
  "name": "Professional (Female)",
39
  "description": "Clear, trustworthy female voice",
40
- "reference_path": "voices/professional_female.wav"
 
 
41
  }
42
  }
43
 
@@ -66,7 +72,8 @@ class TTSRequest(BaseModel):
66
  """TTS synthesis request."""
67
  text: str
68
  voice: str = "professional_male" # Built-in or custom voice ID
69
- exaggeration: float = 0.5 # Emotion intensity (0.0 - 1.0)
 
70
  custom_voice_url: Optional[str] = None # URL to custom voice audio
71
 
72
 
@@ -139,7 +146,12 @@ async def synthesize(request: TTSRequest):
139
  voice_audio = f.read()
140
  logger.info(f"🎤 Using custom voice file: {request.voice}")
141
 
142
- logger.info(f"🎙️ Generating speech: voice={request.voice}, text={request.text[:50]}...")
 
 
 
 
 
143
 
144
  # Generate audio with or without reference
145
  if voice_audio:
@@ -152,14 +164,16 @@ async def synthesize(request: TTSRequest):
152
  wav = model.generate(
153
  text=request.text,
154
  audio_prompt_path=tmp_path,
155
- exaggeration=request.exaggeration
 
156
  )
157
  os.unlink(tmp_path) # Clean up temp file
158
  else:
159
  # No reference - use default voice
160
  wav = model.generate(
161
  text=request.text,
162
- exaggeration=request.exaggeration
 
163
  )
164
 
165
  # Convert to MP3
 
22
  version="1.1.0"
23
  )
24
 
25
+ # Built-in voices (multilingual) with voice-specific settings
26
  BUILTIN_VOICES = {
27
  "professional_male": {
28
  "name": "Professional (Male)",
29
  "description": "Confident business voice, works well in Russian/English",
30
+ "reference_path": "voices/professional_male.wav",
31
+ "exaggeration": 0.4, # Calm, controlled
32
+ "cfg_weight": 0.5
33
  },
34
  "friendly_male": {
35
  "name": "Friendly (Male)",
36
  "description": "Warm, approachable voice for building rapport",
37
+ "reference_path": "voices/friendly_male.wav",
38
+ "exaggeration": 0.7, # More expressive
39
+ "cfg_weight": 0.4
40
  },
41
  "professional_female": {
42
  "name": "Professional (Female)",
43
  "description": "Clear, trustworthy female voice",
44
+ "reference_path": "voices/professional_female.wav",
45
+ "exaggeration": 0.5, # Balanced
46
+ "cfg_weight": 0.5
47
  }
48
  }
49
 
 
72
  """TTS synthesis request."""
73
  text: str
74
  voice: str = "professional_male" # Built-in or custom voice ID
75
+ exaggeration: Optional[float] = None # Override emotion intensity (0.0 - 1.0)
76
+ cfg_weight: Optional[float] = None # Classifier-free guidance (0.0 - 1.0)
77
  custom_voice_url: Optional[str] = None # URL to custom voice audio
78
 
79
 
 
146
  voice_audio = f.read()
147
  logger.info(f"🎤 Using custom voice file: {request.voice}")
148
 
149
+ # Get voice-specific parameters or use defaults
150
+ voice_config = BUILTIN_VOICES.get(request.voice, {})
151
+ exaggeration = request.exaggeration if request.exaggeration is not None else voice_config.get("exaggeration", 0.5)
152
+ cfg_weight = request.cfg_weight if request.cfg_weight is not None else voice_config.get("cfg_weight", 0.5)
153
+
154
+ logger.info(f"🎙️ Generating: voice={request.voice}, exaggeration={exaggeration}, cfg={cfg_weight}, text={request.text[:50]}...")
155
 
156
  # Generate audio with or without reference
157
  if voice_audio:
 
164
  wav = model.generate(
165
  text=request.text,
166
  audio_prompt_path=tmp_path,
167
+ exaggeration=exaggeration,
168
+ cfg_weight=cfg_weight
169
  )
170
  os.unlink(tmp_path) # Clean up temp file
171
  else:
172
  # No reference - use default voice
173
  wav = model.generate(
174
  text=request.text,
175
+ exaggeration=exaggeration,
176
+ cfg_weight=cfg_weight
177
  )
178
 
179
  # Convert to MP3