forked from devnen/Chatterbox-TTS-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
113 lines (96 loc) · 4.3 KB
/
models.py
File metadata and controls
113 lines (96 loc) · 4.3 KB
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
# File: models.py
# Pydantic models for API request and response validation.
from typing import Optional, Literal
from pydantic import BaseModel, Field
class GenerationParams(BaseModel):
"""Common parameters for TTS generation."""
temperature: Optional[float] = Field(
None, # Defaulting to None means server will use config default if not provided
ge=0.0,
le=1.5, # Based on Chatterbox Gradio app for temperature
description="Controls randomness. Lower is more deterministic. (Range: 0.0-1.5)",
)
exaggeration: Optional[float] = Field(
None,
ge=0.25, # Based on Chatterbox Gradio app
le=2.0, # Based on Chatterbox Gradio app
description="Controls expressiveness/exaggeration. (Range: 0.25-2.0)",
)
cfg_weight: Optional[float] = Field(
None,
ge=0.2, # Based on Chatterbox Gradio app
le=1.0, # Based on Chatterbox Gradio app
description="Classifier-Free Guidance weight. Influences adherence to prompt/style and pacing. (Range: 0.2-1.0)",
)
seed: Optional[int] = Field(
None,
ge=0, # Seed should be non-negative, 0 often implies random.
description="Seed for generation. 0 may indicate random behavior based on engine.",
)
speed_factor: Optional[float] = Field(
None,
ge=0.25,
le=4.0,
description="Speed factor for the generated audio. 1.0 is normal speed. Applied post-generation.",
)
language: Optional[str] = Field(
None,
description="Language of the text. (Primarily for UI, actual engine may infer)",
)
class CustomTTSRequest(BaseModel):
"""Request model for the custom /tts endpoint."""
text: str = Field(..., min_length=1, description="Text to be synthesized.")
voice_mode: Literal["predefined", "clone"] = Field(
"predefined", # Default voice mode
description="Voice mode: 'predefined' for a built-in voice, 'clone' for voice cloning using a reference audio.",
)
predefined_voice_id: Optional[str] = Field(
None,
description="Filename of the predefined voice to use (e.g., 'default_sample.wav'). Required if voice_mode is 'predefined'.",
)
reference_audio_filename: Optional[str] = Field(
None,
description="Filename of a user-uploaded reference audio for voice cloning. Required if voice_mode is 'clone'.",
)
output_format: Optional[Literal["wav", "opus", "mp3"]] = Field( # Added "mp3"
"wav", description="Desired audio output format." # Default output format
)
split_text: Optional[bool] = Field(
True, # Default to splitting enabled
description="Whether to automatically split long text into chunks for processing.",
)
chunk_size: Optional[int] = Field(
120, # Default target chunk size from config
ge=50, # Minimum reasonable chunk size
le=500, # Maximum reasonable chunk size
description="Approximate target character length for text chunks when splitting is enabled (50-500).",
)
# Embed generation parameters directly
temperature: Optional[float] = Field(
None, description="Overrides default temperature if provided."
)
exaggeration: Optional[float] = Field(
None, description="Overrides default exaggeration if provided."
)
cfg_weight: Optional[float] = Field(
None, description="Overrides default CFG weight if provided."
)
seed: Optional[int] = Field(None, description="Overrides default seed if provided.")
speed_factor: Optional[float] = Field(
None, description="Overrides default speed factor if provided."
)
language: Optional[str] = Field(
None, description="Overrides default language if provided."
)
class ErrorResponse(BaseModel):
"""Standard error response model for API errors."""
detail: str = Field(..., description="A human-readable explanation of the error.")
class UpdateStatusResponse(BaseModel):
"""Response model for status updates, e.g., after saving settings."""
message: str = Field(
..., description="A message describing the result of the operation."
)
restart_needed: Optional[bool] = Field(
False,
description="Indicates if a server restart is recommended or required for changes to take full effect.",
)