user = $user; } public function getSpellingWord() { $difficulty = $this->difficulty(); $question = e107::getDb()->retrieve("SELECT `word`,`usage`, IFNULL(`cnt`,'0') AS Ncnt FROM (SELECT `word`,`usage` FROM e107.e107_tk_wordList WHERE `year` <= '".ceil($difficulty)."' AND `usage` != '') AS wList LEFT JOIN (SELECT `answer`,COUNT(`answer`)AS `cnt` FROM e107.e107_tkReport WHERE `answereddatestamp` > unix_timestamp((NOW()) - INTERVAL 1 MONTH) AND `username` = '".$this->user."' AND `subject` = 'spelling' GROUP BY `answer` ORDER BY COUNT(`answer`)) AS Ans ON wList.`word` = Ans.`answer` ORDER BY IFNULL(`cnt`,'0'), RAND() LIMIT 1;"); $questionHtml = $this->spellingHtml($question); e107::getDb()->insert('tkLastQuestion', ['user'=>$this->user,'LastQuestionHtml'=>base64_encode($questionHtml)]); e107::getRender()->tablerender('Spelling', $questionHtml); } /** * Create a spelling form using the supplied question. * And write it into "$this->returnQuestion". * * @param array() $data Question data to be used. */ private function spellingHtml($data) { $tp = e107::getParser(); $frm = e107::getForm(); $fString = $frm->open('questionForm', 'post', '', ['autocomplete' => 'off', 'class' => 'formclass']); $fString .= $frm->label('

Spelling

') . "
\n"; $fString .= $frm->label('Spell the word in the sentence.') . "\n"; $fString .= '
'; //if (!file_exists('./audio/' . md5($data['word']) . '3v.wav')) { //exec('./audio/flite-2.0.0-release/bin/flite -voice ./audio/voices/cmu_us_aew.flitevox -o "./audio/' . md5($data['word']) . '3v.wav" "Spell the word, ' . $tp->toHTML($data['word']) . '. ' . $tp->toHTML($data['usage']) . '"'); //} if (!file_exists('./audio/' . md5($data['word']) . '.mp3')) { $voices = ['bf_emma','bf_isabella','bf_alice','bf_lily','bm_george','bm_lewis','bm_daniel','bm_fable']; $voice = $voices[array_rand($voices,1)]; exec('curl http://192.168.1.252:8880/v1/audio/speech -H "Content-Type: application/json" -d \'{"model":"tts-1","input":"Spell the word, ' . $tp->toHTML($data['word']) . '. ' . $tp->toHTML($data['usage']) . '.","voice":"'.$voice.'"}\' --output ./audio/' . md5($data['word']) . '.mp3'); } $fString .= "\n"; $fString .= '

'; $fString .= $frm->text('a1', '', 80, ['placeholder' => 'Write answer here!', 'autocomplete' => "off", 'spellcheck' => "false"]) . "\n"; $fString .= $frm->hidden('checkerData', TkAnswerStore::issue($this->user, $data), ['id' => 'checkerData']); $fString .= $frm->hidden('subject', 'spelling', ['id' => 'subject']); $fString .= '
' . "\n"; $fString .= e107::getForm()->button('Answer', 'Check answer') . "\n"; $fString .= e107::getForm()->close(); $fString .= '

'; return $fString; } /** * Return the difficulty based on previously answered questions. * * @return array['percent','count'] Difficulty 1-13, Number of questions answered. */ private function difficulty() { $stats = e107::getDb()->retrieve("SELECT (SUM(correct)/COUNT(correct)*13) as percent, COUNT(correct) as count FROM e107.`e107_tkReport` WHERE answereddatestamp >= unix_timestamp((NOW()) - INTERVAL 1 MONTH) AND `username` = '$this->user' AND `subject` = 'spelling';" ); if($stats["count"]>=300) { return $stats["percent"]; } elseif($stats["count"]>=250) { return min($stats["percent"],7); } elseif($stats["count"]>=200) { return min($stats["percent"],5); } elseif($stats["count"]>=100) { return min($stats["percent"],3); } else { return 1; } } }