public function getText() { $params = JComponentHelper::getParams('com_localise'); $clientID = $params->get('clientID'); $secret = $params->get('client_secret'); if (empty($clientID) || empty($secret)) { $this->setError(JText::_('COM_LOCALISE_MISSING_CLIENTID_SECRET')); return ''; } $app = JFactory::getApplication(); $text = $app->input->getHtml('text'); if (empty($text)) { $this->setError(JText::_('COM_LOCALISE_MISSING_TEXT')); return ''; } $to = $app->input->getCmd('to'); if (empty($to)) { $this->setError(JText::_('COM_LOCALISE_MISSING_TO_LANGUAGECODE')); return ''; } $from = $app->input->getCmd('from'); class_exists('HTTPTranslator') or (require dirname(__DIR__) . '/helpers/azuretranslator.php'); $translator = new HTTPTranslator(); return $translator->translate($clientID, $secret, $to, $text, $from); }
<?php require_once '../application/MScredentials.php'; require_once '../application/HTTPTranslator.php'; try { //Set the params $toLanguage = "en"; $inputStr = "Esto es una mesa"; //Create the Translator Object. $translatorObj = new HTTPTranslator($clientID, $clientSecret, TRUE); // 1.- Translate String $translatedStr = $translatorObj->translate($inputStr, $toLanguage); echo "OK. Translation " . $inputStr . " ===> " . $translatedStr . "\n"; // 2.- Detect Language $languageCode = $translatorObj->detectLanguage($inputStr); echo "OK. Language detection " . $inputStr . " ===> " . $languageCode . "\n"; // 3.- Speak in Spanish $mp3 = $translatorObj->speak($translatedStr, 'en'); echo "OK. Speak " . $translatedStr . " ===> " . "\n"; $fp = fopen('../data/data.mp3', 'w'); fwrite($fp, $mp3); fclose($fp); exec('"C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe" -Idummy C:\\Users\\Javier\\git\\WhatsAppTranslate\\WhatsAppTranslate\\data\\data.mp3'); } catch (Exception $e) { echo "Error. Exception: " . $e->getMessage() . PHP_EOL; }