Skip to content

Commit

Permalink
Plugin: Text2Speech: Don't integrate directly with AIHelper plugin - …
Browse files Browse the repository at this point in the history
…refs #4622
  • Loading branch information
AngelFQC committed Mar 5, 2023
1 parent db51744 commit eb5a1d3
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions plugin/ai_helper/tool/learnpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@

require_once __DIR__.'/../../../main/inc/global.inc.php';
require_once __DIR__.'/../AiHelperPlugin.php';
require_once __DIR__.'/../../text2speech/Text2SpeechPlugin.php';
require_once api_get_path(SYS_CODE_PATH).'exercise/export/aiken/aiken_classes.php';
require_once api_get_path(SYS_CODE_PATH).'exercise/export/aiken/aiken_import.inc.php';

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

$plugin = AiHelperPlugin::create();

$apiList = $plugin->getApiList();
Expand Down Expand Up @@ -70,19 +66,11 @@
$promptItem = sprintf($messageGetItemContent, $topic, $courseLanguage, $wordsCount, $title);
$resultContentText = $plugin->openAiGetCompletionText($promptItem, 'learnpath');
$lpItemContent = (!empty($resultContentText) ? trim($resultContentText) : '');
$audioControl = '';
if ($isTextToSpeechEnabled && !empty($lpItemContent)) {
$filePath = $text2speechPlugin->convert(strip_tags($lpItemContent));
$audioControl = '<audio controls>'.
'<source src="'.$filePath.'" type="audio/ogg">'.
'Your browser does not support the audio element.'.
'</audio>';
}

if (false !== stripos($lpItemContent, '</head>')) {
$lpItemContent = preg_replace("|</head>|i", "\r\n$style\r\n\\0", $audioControl.$lpItemContent);
$lpItemContent = preg_replace("|</head>|i", "\r\n$style\r\n\\0", $lpItemContent);
} else {
$lpItemContent = '<html><head><title>'.trim($title).'</title>'.$style.'</head><body>'.$audioControl.$lpItemContent.'</body></html>';
$lpItemContent = '<html><head><title>'.trim($title).'</title>'.$style.'</head><body>'.$lpItemContent.'</body></html>';
}
$lpItems[$position]['content'] = $lpItemContent;
$position++;
Expand Down

0 comments on commit eb5a1d3

Please sign in to comment.