tts.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from collections.abc import Generator
  2. from typing import Optional
  3. from dify_plugin import TTSModel
  4. from dify_plugin.errors.model import (
  5. CredentialsValidateFailedError,
  6. )
  7. class {{ .PluginName | SnakeToCamel }}Text2SpeechModel(TTSModel):
  8. """
  9. Model class for OpenAI Speech to text model.
  10. """
  11. def _invoke(
  12. self,
  13. model: str,
  14. credentials: dict,
  15. content_text: str,
  16. voice: str,
  17. user: Optional[str] = None,
  18. ) -> bytes | Generator[bytes, None, None]:
  19. """
  20. _invoke text2speech model
  21. :param model: model name
  22. :param tenant_id: user tenant id
  23. :param credentials: model credentials
  24. :param content_text: text content to be translated
  25. :param voice: model timbre
  26. :param user: unique user id
  27. :return: text translated to audio file
  28. """
  29. pass
  30. def validate_credentials(
  31. self, model: str, credentials: dict, user: Optional[str] = None
  32. ) -> None:
  33. """
  34. validate credentials text2speech model
  35. :param model: model name
  36. :param credentials: model credentials
  37. :param user: unique user id
  38. :return: text translated to audio file
  39. """
  40. try:
  41. pass
  42. except Exception as ex:
  43. raise CredentialsValidateFailedError(str(ex))