Skip to content

Commit d64aae0

Browse files
FraGoTeAngelFQC
authored andcommitted
Text2Speech
1 parent 8abbd0f commit d64aae0

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

plugin/ai_helper/tool/learnpath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
require_once api_get_path(SYS_CODE_PATH).'exercise/export/aiken/aiken_import.inc.php';
1515

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

1919
$plugin = AiHelperPlugin::create();
2020

plugin/text2speech/Text2SpeechPlugin.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class Text2SpeechPlugin extends Plugin
1010
{
1111
public const MOZILLATTS_API = 'mozillatts';
12-
public const PATH_TO_SAVE_FILES = __DIR__.'/files/';
12+
public const PATH_TO_SAVE_FILES = __DIR__.'/../../app/upload/plugins/text2speech/';
1313

1414
protected function __construct()
1515
{
@@ -52,7 +52,7 @@ public function getApiList()
5252
*/
5353
public function convert(string $text)
5454
{
55-
$path = '/plugin/text2speech/files/';
55+
$path = '/app/upload/plugins/text2speech/';
5656
switch ($this->get('api_name')) {
5757
case self::MOZILLATTS_API:
5858
require_once __DIR__.'/src/mozillatts/MozillaTTS.php';
@@ -101,7 +101,8 @@ public function install()
101101
public function uninstall()
102102
{
103103
if (file_exists(self::PATH_TO_SAVE_FILES)) {
104-
unlink(self::PATH_TO_SAVE_FILES);
104+
array_map('unlink', glob(self::PATH_TO_SAVE_FILES. '/*.*'));
105+
rmdir(self::PATH_TO_SAVE_FILES);
105106
}
106107
}
107108
}

plugin/text2speech/src/mozillatts/MozillaTTS.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ private function request(string $data): string
2424
{
2525
$filename = uniqid().'.wav';
2626
$filePath = $this->filePath.$filename;
27-
file_put_contents($filePath, file_get_contents(
28-
$this->url.'?api_key='.urlencode($this->apiKey).
29-
'&text='.str_replace('%0A', '+', urlencode($data))
30-
));
27+
$resource = fopen($filePath, 'w');
28+
29+
$client = new GuzzleHttp\Client();
30+
$client->get($this->url.'?api_key='.urlencode($this->apiKey).
31+
'&text='.str_replace('%0A', '+', urlencode($data)), [
32+
'headers' => [
33+
'Cache-Control' => 'no-cache',
34+
'Content-Type' => 'audio/wav'
35+
],
36+
'sink' => $resource,
37+
]);
3138

3239
return $filename;
3340
}

0 commit comments

Comments
 (0)