Forum des Objets Communicants et Solutions pour les Libérer...
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.

Forum des Objets Communicants et Solutions pour les Libérer...


 
AccueilAccueil  GalerieGalerie  RechercherRechercher  Dernières imagesDernières images  S'enregistrerS'enregistrer  Connexion  
-40%
Le deal à ne pas rater :
Tefal Ingenio Emotion – Batterie de cuisine 10 pièces (induction, ...
59.99 € 99.99 €
Voir le deal

 

 [EN DEV] Envoi de message à un Karotz

Aller en bas 
AuteurMessage
Mephisto
Silver Nabz
Silver Nabz
Mephisto


Age : 43
Localisation : Golbey (88)
Nabaztag : Aiko [Tag²] & Océane de Rigosa Rives [Karotz]
Nbr de messages : 311
Carottes : 5567

[EN DEV] Envoi de message à un Karotz Empty
MessageSujet: [EN DEV] Envoi de message à un Karotz   [EN DEV] Envoi de message à un Karotz Icon_minitimeVen 16 Déc 2011 - 11:12

Bonjour à toutes et à tous,

Vous trouverez ci-dessous un class php permettant d'envoyer un message à un Karotz. Je me base sur l'api de Wizz.cc.

Code:
<?php

class Lapin {

   private $Kz_Nom      = null;
   private $Kz_Token      = null;
   private $Kz_Voix      = "voice=fr";
   private $Kz_Type_Voix   = 1;
   private $Kz_Msg      = null;
   private $Kz_tts         = null;

   function __contruct() {}

   function LeLapin($Son_Nom,$Son_Token = null)
   {
      $this->Kz_Nom = "sn=".$Son_Nom;                              // Le nom du Karotz
      if(isset($Son_Token)) {$this->Kz_Token = "&token=".$Son_Token;   }      // Le token du Karotz
   }

   function Voix($Type_Voix,$La_Voix)
   {
      
      $this->Kz_Type_Voix = $Type_Voix;

      $La_Voix--;
      
      switch($Type_Voix) {
         case 1:
            $voix = array("fr","en","de","es");
            $this->Kz_Voix = "&voice=".$voix[$La_Voix];
            break;
         case 2:
            $voix = array("bicool","chuchotement","darkvadoor","electra",
                  "guy_vieux","guy_voix_basse","guy_fort","guy_grave",
                  "helium","jose","juliexp","julieEnfant","loic","mamie",
                  "manuella","matteo","narbe","nono","papanoel","philippe","ramboo","samy","sidoo");
            $this->Kz_Voix = "&ws_kajedo=".$voix[$La_Voix];
            break;
         default:
            break;
      }
   }

   function Texte($LeTexte)
   {
      $tmp_msg = explode(" ",$LeTexte);
      for($x=0;$x<sizeof($tmp_msg);$x++) { $this->Kz_tts .= "+" . $tmp_msg[$x].","; }
   }

   function PrepareURL()
   {
      if($this->Kz_Type_Voix == 2) { $this->Kz_tts .= ",+Fin."; } else { $this->Kz_tts .="."; }

      $url = "http://api.wizz.cc/?";
      $url .= $this->Kz_Nom;
      if(isset($this->Kz_Token))
      {      
         $url .= $this->Kz_Token;
      }
      $url .= "&tts=".$this->Kz_tts.$this->Kz_Voix;
      return $url;
   }


   function EnvoiMsgKz()
   {
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL,$this->PrepareURL() );
      curl_setopt($curl, CURLINFO_HEADER_OUT, true);
      curl_setopt($curl, CURLOPT_HEADER, false);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
      $result = curl_exec($curl);
      if(!$curl)
      {
         echo "ERREUR : ". curl_error($curl);
         curl_close($curl);
         exit();
      }
      $curl_info = curl_getinfo($curl);
      curl_close($curl);
   }
}
?>

Utilisation

1) On initalise la class
Citation :
$kz = new Lapin();

2) On déclare le Karotz (Nom, Token)
Citation :
$kz->LeLapin("NomKz",TokenKz);

3) On choix la voix (Type de voix standard ou kajedo, la voix)
Citation :
$kz->Voix(TypeVoix,Voix);

TYPE VOIX
Numéro Type voix
1 Standard
2 Kajedo

VOIX STANDARD
Numéro voix
1 Français
2 Anglais
3 Allemand
4 Espagnol

VOIX KAJEDO
1 bicool
2 chuchotement
3 darkvadoor
4 electra
5 guy_vieux
6 guy_voix_basse
7 guy_fort
8 guy_grave
9 helium
10 jose
11 juliexp
12 julieEnfant
13 loic
14 mamie
15 manuella
16 matteo
17 narbe
18 nono
19 papanoel
20 philippe
21 ramboo
22 samy
23 sidoo

3) Le message

Pour l'instant il ne gère pas les caractères accentués, pour le moment.

Citation :
$kz->Texte(Le Message);

4) On envoi le message

Citation :
$kz->EnvoiMsg();

A venir

* Gestion de la liste complète des voix
* Gestion du Nabaztag:tag

Liste non exhaustive.

Bonne journée
Revenir en haut Aller en bas
Mephisto
Silver Nabz
Silver Nabz
Mephisto


Age : 43
Localisation : Golbey (88)
Nabaztag : Aiko [Tag²] & Océane de Rigosa Rives [Karotz]
Nbr de messages : 311
Carottes : 5567

[EN DEV] Envoi de message à un Karotz Empty
MessageSujet: Re: [EN DEV] Envoi de message à un Karotz   [EN DEV] Envoi de message à un Karotz Icon_minitimeVen 16 Déc 2011 - 15:22

Je viens de faire une modif.

C'est bien beau de vouloir envoyer un message à la bestiole si elle n'est pas en ligne.

Code:
<?php

class Lapin {

   private $Kz_Nom      = null;
   private $Kz_Token      = null;
   private $Kz_Voix      = "voice=fr";
   private $Kz_Type_Voix   = 1;
   private $Kz_Msg      = null;
   private $Kz_tts         = null;
   private $Kz_Url         = null;

   const URL_API         = "http://api.wizz.cc/?";

   function __contruct() {}

   function LeLapin($Son_Nom,$Son_Token = null)
   {
      $this->Kz_Nom = "sn=".$Son_Nom;                              // Le nom du Karotz
      if(isset($Son_Token)) {$this->Kz_Token = "&token=".$Son_Token;   }      // Le token du Karotz
   }

   function Voix($Type_Voix,$La_Voix)
   {
      
      $this->Kz_Type_Voix = $Type_Voix;

      $La_Voix--;
      
      switch($Type_Voix) {
         case 1:
            $voix = array("fr","en","de","es");
            $this->Kz_Voix = "&voice=".$voix[$La_Voix];
            break;
         case 2:
            $voix = array("bicool","chuchotement","darkvadoor","electra",
                  "guy_vieux","guy_voix_basse","guy_fort","guy_grave",
                  "helium","jose","juliexp","julieEnfant","loic","mamie",
                  "manuella","matteo","narbe","nono","papanoel","philippe","ramboo","samy","sidoo");
            $this->Kz_Voix = "&ws_kajedo=".$voix[$La_Voix];
            break;
         default:
            break;
      }
   }

   function Texte($LeTexte)
   {
      $tmp_msg = explode(" ",$LeTexte);
      for($x=0;$x<sizeof($tmp_msg);$x++) { $this->Kz_tts .= "+" . $tmp_msg[$x].","; }
   }

   function PrepareURL($Commande)
   {
      switch($Commande) {
         case "check":
            $url = self::URL_API . $this->Kz_Nom . $this->Kz_Token . "&check";
            break;
         case "msg":
            $url = self::URL_API . $this->Kz_Nom . $this->Kz_Token;
            if($this->Kz_Type_Voix == 2) { $this->Kz_tts .= ",+Fin."; } else { $this->Kz_tts .="."; }
            $url .= "&tts=".$this->Kz_tts.$this->Kz_Voix;
            break;            
      }
      return $url;            
   }

   function EnvoiCommande($Commande) {
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL,$this->PrepareURL($Commande) );
      curl_setopt($curl, CURLOPT_HEADER, false);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
      curl_setopt($curl, CURLINFO_HEADER_OUT, true);
      $result = curl_exec($curl);
      if(!$curl)
      {
         echo "ERREUR : ". curl_error($curl);
         curl_close($curl);
         exit();
      }
      $curl_info = curl_getinfo($curl);
      curl_close($curl);
      return $result;
   }
}
?>

Pour utiliser la class

Code:
$kz = new Lapin();
$kz->LeLapin(NomLapin,TokenLapin);
$enligne = $kz->EnvoiCommande("check");
if($enligne == "Karotz en ligne.") {
   $kz->Voix(TypeVoix,Voix);
   $kz->Texte(LeMessage);
        $EnvoiMsg = $kz->EnvoiCommande("msg");
   if($EnvoiMsg == "Message MP3 lu par le Karotz.") {
      print("InfKz : Message envoyé !");
   } else {
      print("ErrKz : Message non envoyé > " . $EnvoiMsg);
   }
} else {
   print("ErrKz : " . $enligne."\r\n" );
}

Je récupère le retour de curl dans une variable nomée $enligne. Si j'ai Karotz en ligne. alors je continue sinon j'affiche un message avec l'erreur retournée par curl

Un peu plus bas, si curl me renvoi Message MP3 lu par le Karotz. alors j'affiche Message envoyé sinon message d'erreur.
Revenir en haut Aller en bas
Mephisto
Silver Nabz
Silver Nabz
Mephisto


Age : 43
Localisation : Golbey (88)
Nabaztag : Aiko [Tag²] & Océane de Rigosa Rives [Karotz]
Nbr de messages : 311
Carottes : 5567

[EN DEV] Envoi de message à un Karotz Empty
MessageSujet: Re: [EN DEV] Envoi de message à un Karotz   [EN DEV] Envoi de message à un Karotz Icon_minitimeSam 17 Déc 2011 - 2:32

Encore de modifs, avec la prise en charge des tag:tag

Code:
<?php

class Lapin {

   private $Kz_Nom         = null;
   private $Kz_Token      = null;
   private $Kz_Voix      = "voice=fr";
   private $Kz_Type_Voix      = 1;
   private $Kz_Msg         = null;
   private $Kz_tts         = null;
   private $Kz_Url         = null;
   private $Kz_Lapin_Type      = 2;
   private $Kz_Serveur      = null;

   const URL_API         = "http://api.wizz.cc/?";

   function __contruct() {}

   function LeLapin($Son_Nom,$Son_Token = null)
   {
      $this->Kz_Nom = "sn=".$Son_Nom;                     // Le nom du Karotz
      if(isset($Son_Token)) {$this->Kz_Token = "&token=".$Son_Token;   }      // Le token du Karotz
      if(isset($$Son_Serveur)) {$this->Kz_Server = "&server=".$Son_Serveur;   }   // Le token du Karotz
   }

   function Serveur($Son_Serveur) { $this->Kz_Serveur = $Son_Serveur; }
   
   function TypeLapin($SonType) {$this->Kz_Lapin_Type = $SonType; }
   
   function Voix($Type_Voix,$La_Voix)
   {
      
      $this->Kz_Type_Voix = $Type_Voix;

      $La_Voix--;
      
      switch($Type_Voix) {
         case 1:
            $voix = array("fr","en","de","es");
            $this->Kz_Voix = "&voice=".$voix[$La_Voix];
            break;
         case 2:
            $voix = array("bicool","chuchotement","darkvadoor","electra",
                  "guy_vieux","guy_voix_basse","guy_fort","guy_grave",
                  "helium","jose","juliexp","julieEnfant","loic","mamie",
                  "manuella","matteo","narbe","nono","papanoel","philippe","ramboo","samy","sidoo");
            $this->Kz_Voix = "&ws_kajedo=".$voix[$La_Voix];
            break;
         default:
            break;
      }
   }

   function Texte($LeTexte)
   {
      $tmp_msg = explode(" ",$LeTexte);
      for($x=0;$x<sizeof($tmp_msg);$x++) { $this->Kz_tts .= "+" . $tmp_msg[$x].","; }
   }

   function PrepareURL($Commande)
   {
      switch($Commande) {
         case "check":
            $url = self::URL_API . $this->Kz_Nom . $this->Kz_Token . "&check";
            break;
         case "msg":
            $url = self::URL_API . $this->Kz_Nom . $this->Kz_Token . $this->Kz_Serveur;
            
               if($this->Kz_Type_Voix == 2 && $this->Kz_Lapin_Type == 2) {
                  $this->Kz_tts .= ",+Fin.";
               } else {
                  $this->Kz_tts .=".";
               }
            
            $url .= "&tts=".$this->Kz_tts.$this->Kz_Voix;
            break;            
      }
      return $url;            
   }

   function EnvoiCommande($Commande) {
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL,$this->PrepareURL($Commande) );
      curl_setopt($curl, CURLOPT_HEADER, false);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
      curl_setopt($curl, CURLINFO_HEADER_OUT, true);
      $result = curl_exec($curl);
      if(!$curl)
      {
         echo "ERREUR : ". curl_error($curl);
         curl_close($curl);
         exit();
      }
      $curl_info = curl_getinfo($curl);
      curl_close($curl);
      return $result;
   }
}
?>
Revenir en haut Aller en bas
Contenu sponsorisé





[EN DEV] Envoi de message à un Karotz Empty
MessageSujet: Re: [EN DEV] Envoi de message à un Karotz   [EN DEV] Envoi de message à un Karotz Icon_minitime

Revenir en haut Aller en bas
 
[EN DEV] Envoi de message à un Karotz
Revenir en haut 
Page 1 sur 1
 Sujets similaires
-
» Envoi de message par le web
» Plus d'envoi de message ?
» Envoi de message automatique
» Envoi et réception de message...
» envoi de message par mail

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
Forum des Objets Communicants et Solutions pour les Libérer... :: II. Nabaztag, Karotz, mir:ror, Dal:Dal (Violet Object Operating System) :: L'univers de Nabaztag :: Archives :: API :: /dev :: J'ai fait un script, une application... Vous pouvez commenter, questionner !-
Sauter vers: