@link http://blog.idleman.fr @licence CC by nc sa @version 1.0.0 @description Permet l'ajout de phrases à yana et la définition des conséquences de ces phrases */ function speechcommands_vocal_command(&$response,$actionUrl){ global $conf; require_once('SpeechCommand.class.php'); $command = new SpeechCommand(); $commands = $command->populate(); foreach($commands as $command){ if($command->state !=1) continue; $response['commands'][] = array( 'command'=>$conf->get('VOCAL_ENTITY_NAME').' '.$command->command, 'url'=>$actionUrl.'?action=speechcommands_execute&command='.$command->id,'confidence'=>($command->confidence+$conf->get('VOCAL_SENSITIVITY')) ); } } function speechcommands_action(){ global $_,$conf,$myUser; switch($_['action']){ case 'plugin_speechcommands_save': if(!$myUser->can('speech_command','c')) exit('Permissions insufisantes'); require_once('SpeechCommand.class.php'); $command = new SpeechCommand(); $command = !empty($_['id']) ? $command->getById($_['id']): new SpeechCommand(); $command->command= $_['command']; $command->action = $_['type']; $command->parameter = $_['parameter']; $command->confidence = $_['confidence']; $command->state = $_['state']=='on'?1:0; $command->save(); header('location: setting.php?section=speechcommands'); break; case 'plugin_speechcommands_delete' : if(!$myUser->can('speech_command','d')) exit('Permissions insufisantes'); require_once('SpeechCommand.class.php'); $command = new SpeechCommand(); $command->delete(array('id'=>$_['id'])); header('location: setting.php?section=speechcommands'); break; case 'speechcommands_execute': global $_; require_once('SpeechCommand.class.php'); $command = new SpeechCommand(); $command = $command->getById($_['command']); set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) { // error was suppressed with the @-operator if (0 === error_reporting()) { return false; } throw new ErrorException($errstr, 0, $errno, $errfile, $errline); }); try{ switch($command->action){ case 'talk': $response = array( 'responses'=>array( array('type'=>'talk', 'sentence'=>$command->parameter ) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'gpio': list($pin,$value) = explode(',',$command->parameter); Gpio::write($pin,$value,true); break; case 'server_command': $result = System::commandSilent(html_entity_decode($command->parameter)); $response = array( 'responses'=>array( array('type'=>'talk', 'sentence'=>utf8_encode($result) ) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'client_command': $response = array( 'responses'=>array( array('type'=>'command', 'program'=>$command->parameter ) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'sound': $response = array( 'responses'=>array( array('type'=>'sound', 'file'=>$command->parameter ) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; case 'url': $content = file_get_contents($command->parameter); $response = array( 'responses'=>array( array('type'=>'talk', 'sentence'=>$content ) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); break; default: throw new Exception('Aucun action n\'est spécifiée'); break; } }catch(Exception $e){ $response = array( 'responses'=>array( array('type'=>'talk', 'sentence'=>Personality::response('WORRY_EMOTION').', le problème viens de : '.$e->getMessage() ) ) ); $json = json_encode($response); echo ($json=='[]'?'{}':$json); } break; } } function speechcommands_plugin_preference_menu(){ global $_; echo '
  • Commandes Vocales
  • '; } function speechcommands_plugin_preference_page(){ global $myUser,$_,$conf; if((isset($_['section']) && $_['section']=='speechcommands' ) ){ if($myUser!=false){ require_once('SpeechCommand.class.php'); $command = new SpeechCommand(); $commands = $command->populate(); $command->state = 1; $command->confidence = '0.8'; $command = isset($_['id'])?$command->getById($_['id']):$command; ?>
    Commandes
    Commande Confidence Action Parametre Etat
    get('VOCAL_ENTITY_NAME').', ' ?> state=='1'?'checked=""checked""':''; ?> />
    get('VOCAL_ENTITY_NAME').', '.$command->command; ?> confidence; ?> action; ?> parameter; ?> state=='1'?'Actif':'Inactif'; ?>

    Explications

    Ce plugin permet d'ajouter des actions en fonction de certaines phrases prononcées que vous pouvez choisir et ajouter à l\'infini.

    Notez bien que ce plugin est optimisé pour yana android et qu'en fonction de l'action souhaitée, celle ci s'execute sur le serveur ou sur le client ( Ceci est spéficié dans l'action à choisir).

    Examples

    Vous devez être connecté