speech.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * audio class
  4. *
  5. * @method null download
  6. */
  7. if (!class_exists('speech')) {
  8. class speech {
  9. /**
  10. * declare private variables
  11. */
  12. private $api_key;
  13. /** @var string $engine */
  14. private $engine;
  15. /** @var template_engine $object */
  16. private $speech_object;
  17. private $settings;
  18. public $audio_path;
  19. public $audio_filename;
  20. public $audio_format;
  21. public $audio_model;
  22. public $audio_voice;
  23. public $audio_language;
  24. public $audio_message;
  25. /**
  26. * called when the object is created
  27. */
  28. public function __construct(settings $settings = null) {
  29. //make the setting object
  30. if ($settings === null) {
  31. $settings = new settings();
  32. }
  33. //add the settings object to the class
  34. $this->settings = $settings;
  35. //build the setting object and get the recording path
  36. $this->api_key = $settings->get('speech', 'api_key');
  37. $this->engine = $settings->get('speech', 'engine');
  38. }
  39. /**
  40. * get_voices - get the list voices
  41. */
  42. public function get_voices() : array {
  43. //set the class interface to use the _template suffix
  44. $classname = 'speech_'.$this->engine;
  45. //create the object
  46. $object = new $classname($this->settings);
  47. //return the voices array
  48. return $object->get_voices();
  49. }
  50. /**
  51. * get_voices - get the list voices
  52. */
  53. public function get_models() : array {
  54. //set the class interface to use the _template suffix
  55. $classname = 'speech_'.$this->engine;
  56. //create the object
  57. $object = new $classname($this->settings);
  58. //return the voices array
  59. return $object->get_models();
  60. }
  61. /**
  62. * is_translate_enabled - get whether the engine can do translations
  63. */
  64. public function is_translate_enabled() : bool {
  65. //set the class interface to use the _template suffix
  66. $classname = 'speech_'.$this->engine;
  67. //create the object
  68. $object = new $classname($this->settings);
  69. //return the translate_enabled
  70. return $object->is_translate_enabled();
  71. }
  72. /**
  73. * is_language_enabled - get whether the engine allows to set the language
  74. */
  75. public function is_language_enabled() : bool {
  76. //set the class interface to use the _template suffix
  77. $classname = 'speech_'.$this->engine;
  78. //create the object
  79. $object = new $classname($this->settings);
  80. //return the language_enabled
  81. return $object->is_language_enabled();
  82. }
  83. /**
  84. * get_languages - get the list languages
  85. */
  86. public function get_languages() : array {
  87. //set the class interface to use the _template suffix
  88. $classname = 'speech_'.$this->engine;
  89. //create the object
  90. $object = new $classname($this->settings);
  91. //return the languages array
  92. return $object->get_languages();
  93. }
  94. /**
  95. * speech - text to speech
  96. */
  97. public function speech() {
  98. if (!empty($this->engine)) {
  99. //set the class interface to use the _template suffix
  100. $class_name = 'speech_'.$this->engine;
  101. //create the object
  102. $object = new $class_name($this->settings);
  103. //ensure the class has implemented the speech_interface interface
  104. if ($object instanceof speech_interface) {
  105. $object->set_path($this->audio_path);
  106. $object->set_filename($this->audio_filename);
  107. $object->set_format($this->audio_format);
  108. $object->set_voice($this->audio_voice);
  109. //$object->set_model($this->audio_model);
  110. //$object->set_language($this->audio_language);
  111. //$object->set_translate($this->audio_translate);
  112. $object->set_message($this->audio_message);
  113. $object->speech();
  114. }
  115. else {
  116. return false;
  117. }
  118. }
  119. }
  120. }
  121. }
  122. ?>