tts.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (C) 2025 AIDC-AI
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS,
  9. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. # See the License for the specific language governing permissions and
  11. # limitations under the License.
  12. """
  13. TTS API schemas
  14. """
  15. from typing import Optional
  16. from pydantic import BaseModel, Field
  17. class TTSSynthesizeRequest(BaseModel):
  18. """TTS synthesis request"""
  19. text: str = Field(..., description="Text to synthesize")
  20. workflow: Optional[str] = Field(
  21. None,
  22. description="TTS workflow key (e.g., 'runninghub/tts_edge.json' or 'selfhost/tts_edge.json'). If not specified, uses default workflow from config."
  23. )
  24. ref_audio: Optional[str] = Field(
  25. None,
  26. description="Reference audio path for voice cloning (optional). Can be a local file path or URL."
  27. )
  28. voice_id: Optional[str] = Field(
  29. None,
  30. description="Voice ID (deprecated, use workflow instead)"
  31. )
  32. class Config:
  33. json_schema_extra = {
  34. "example": {
  35. "text": "Hello, welcome to Pixelle-Video!",
  36. "workflow": "runninghub/tts_edge.json",
  37. "ref_audio": None
  38. }
  39. }
  40. class TTSSynthesizeResponse(BaseModel):
  41. """TTS synthesis response"""
  42. success: bool = True
  43. message: str = "Success"
  44. audio_path: str = Field(..., description="Path to generated audio file")
  45. duration: float = Field(..., description="Audio duration in seconds")