Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text2Speech Plugin #4622 #4623

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin/ai_helper/tool/learnpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
require_once api_get_path(SYS_CODE_PATH).'exercise/export/aiken/aiken_import.inc.php';

$text2speechPlugin = Text2SpeechPlugin::create();
$isTextToSpeechEnabled = $text2speechPlugin->get_name('tool_enable') && $text2speechPlugin->get_name('tool_lp_enable');
$isTextToSpeechEnabled = $text2speechPlugin->get('tool_enable') && $text2speechPlugin->get('tool_lp_enable');

$plugin = AiHelperPlugin::create();

Expand Down
7 changes: 4 additions & 3 deletions plugin/text2speech/Text2SpeechPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Text2SpeechPlugin extends Plugin
{
public const MOZILLATTS_API = 'mozillatts';
public const PATH_TO_SAVE_FILES = __DIR__.'/files/';
public const PATH_TO_SAVE_FILES = __DIR__.'/../../app/upload/plugins/text2speech/';

protected function __construct()
{
Expand Down Expand Up @@ -52,7 +52,7 @@ public function getApiList()
*/
public function convert(string $text)
{
$path = '/plugin/text2speech/files/';
$path = '/app/upload/plugins/text2speech/';
switch ($this->get('api_name')) {
case self::MOZILLATTS_API:
require_once __DIR__.'/src/mozillatts/MozillaTTS.php';
Expand Down Expand Up @@ -101,7 +101,8 @@ public function install()
public function uninstall()
{
if (file_exists(self::PATH_TO_SAVE_FILES)) {
unlink(self::PATH_TO_SAVE_FILES);
array_map('unlink', glob(self::PATH_TO_SAVE_FILES. '/*.*'));
rmdir(self::PATH_TO_SAVE_FILES);
}
}
}
15 changes: 11 additions & 4 deletions plugin/text2speech/src/mozillatts/MozillaTTS.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ private function request(string $data): string
{
$filename = uniqid().'.wav';
$filePath = $this->filePath.$filename;
file_put_contents($filePath, file_get_contents(
$this->url.'?api_key='.urlencode($this->apiKey).
'&text='.str_replace('%0A', '+', urlencode($data))
));
$resource = fopen($filePath, 'w');

$client = new GuzzleHttp\Client();
$client->get($this->url.'?api_key='.urlencode($this->apiKey).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El api_key es necesario? Cómo lo genero? En mi TTS que tengo no pide api_key y me genera los audios por el api solo con el texto
🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creo que no es necesario y que lo pone solo para abrirlo a la posibilidad de tener uno a futuro (para este u otro servicio)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exacto en este momento no es necesario pero lo dejo abierto por si se necesita en algún otro servicio.

'&text='.str_replace('%0A', '+', urlencode($data)), [
'headers' => [
'Cache-Control' => 'no-cache',
'Content-Type' => 'audio/wav'
],
'sink' => $resource,
]);

return $filename;
}
Expand Down