1. <?php
  2. /**
  3.  *
  4.  * @author        nTechnology.pl <contact [at] ntechnology [dot] pl>
  5.  * @copyright        Copyright (c) 2009, nTechnology.pl
  6.  *
  7.  */
  8.  
  9. class Ivona {
  10.  
  11.    /**
  12.      * Konstruktor
  13.      *
  14.      * @param string $email
  15.      * @param string $haslo
  16.      * @param string $url
  17.      */
  18.  
  19.    function __construct($email, $haslo, $url, $glos) {
  20.  
  21.        $this->client = new SoapClient($url, array('trace' => true, 'exceptions' => true));
  22.  
  23.        $this->glos = $glos;
  24.        $this->email = $email;
  25.        $this->haslo = $haslo;
  26.  
  27.    }
  28.  
  29.    function PobierzToken() {
  30.  
  31.        $input = array('email' => $this->email);
  32.        $token = $this->client->__soapCall('getToken', $input); // pobierz token.
  33.        $md5 = md5(md5($this->haslo).$token);
  34.  
  35.        return array ('token' => $token, 'md5' => $md5);
  36.  
  37.    }
  38.  
  39.    /**
  40.      * Dodanie nowego nagrania.
  41.      *
  42.      * @param string $nazwa
  43.      * @param string $tresc
  44.      *
  45.      * @return string
  46.      */
  47.  
  48.    function DodajNagranie($nazwa, $tresc) {
  49.  
  50.            $data = $this->PobierzToken();
  51.  
  52.            $input = array (
  53.  
  54.                'token' => $data['token'],
  55.                'md5' => $data['md5'],
  56.                'name' => $nazwa,
  57.                'text' => $tresc,
  58.                'voiceId' => $this->glos,
  59.  
  60.            );
  61.  
  62.  
  63.        $licencja = $this->client->__soapCall('addUtterance', $input);
  64.  
  65.        $plik = $this->ZakupLicencje($licencja);
  66.  
  67.        return $plik['url']; // zwraca ścieżkę do pliku audio
  68.  
  69.  
  70.    }
  71.  
  72.    /**
  73.      * Zakup licencje
  74.      *
  75.      * @param integer $id
  76.      *
  77.      * @return array
  78.      */
  79.  
  80.  
  81.    function ZakupLicencje($id) {
  82.  
  83.  
  84.            $data = $this->PobierzToken();
  85.  
  86.  
  87.            $LicencjaInput = array (
  88.  
  89.                'token' => $data['token'],
  90.                'md5' => $data['md5'],
  91.                'utteranceId' => $id,
  92.                'downloadType' => 'many',
  93.                'encoder_name' => 'mp3/22050',
  94.                'license' => 'free',
  95.                'unlimitedClicks' => 'yes',
  96.  
  97.            );
  98.                
  99.  
  100.        return $this->client->__soapCall('buyLicense', $LicencjaInput);
  101.  
  102.    }
  103.  
  104.  
  105.  
  106.    /**
  107.      * Pobierz wszystkie pliki audio.
  108.      *
  109.      * @return array
  110.      */
  111.  
  112.  
  113.    function PokazPliki() {
  114.  
  115.  
  116.            $data = $this->PobierzToken();
  117.  
  118.  
  119.            $input = array (
  120.  
  121.                'token' => $data['token'],
  122.                'md5' => $data['md5'],
  123.  
  124.            );
  125.                
  126.  
  127.        return $this->client->__soapCall('listUtterances', $input);
  128.  
  129.    }
  130.  
  131.  
  132.    /**
  133.      * Usuń plik.
  134.      *
  135.      * @param integer $id
  136.      */
  137.  
  138.  
  139.    function UsunPlik($id) {
  140.  
  141.  
  142.            $data = $this->PobierzToken();
  143.  
  144.  
  145.            $input = array (
  146.  
  147.                'token' => $data['token'],
  148.                'md5' => $data['md5'],
  149.                'utteranceId' => $id,
  150.  
  151.            );
  152.  
  153.        return $this->client->__soapCall('deleteUtterance', $input);
  154.  
  155.    }
  156.  
  157. }
  158. ?>



Prosta klasa do obsługi API: http://www.ivona.com/online/.

Przykładowe użycie:

  1. <?php
  2. $ivona = new Ivona('moj@mail.pl', 'haslo', 'http://www.ivona.com/online/apispwsdl.php', 2);
  3. echo $ivona -> DodajNagranie('test', 'Ja tylko testuję'); // zwróci nam ścieżkę do pliku audio.
  4. ?>