PHP Classes

File: examples/speak.php

Recommend this page to a friend!
  Classes of Sergey Karavay   PHPolyglot   examples/speak.php   Download  
File: examples/speak.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHPolyglot
Translate, correct spelling and speak a given text
Author: By
Last change: Updates:
- fixed some minor issues.
Date: 6 years ago
Size: 755 bytes
 

Contents

Class file image Download
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use
GinoPane\PHPolyglot\PHPolyglot;

try {
   
$phpolyglot = new PHPolyglot();

   
$textToSpeak = 'Hello world';

   
$languageFrom = 'en';

    echo
sprintf("File stored '%s' \n", $phpolyglot->speak($textToSpeak, $languageFrom)->storeFile());
    echo
sprintf("File stored '%s' \n",
       
$phpolyglot->speak($textToSpeak, $languageFrom, 'flac', ['gender' => 'f'])->storeFile()
    );
    echo
sprintf("File stored '%s' \n",
       
$phpolyglot->speak($textToSpeak, $languageFrom, 'ogg', ['voice' => 'en-US_MichaelVoice'])->storeFile()
    );
} catch (
Exception $exception) {
   
$errorMessage = $exception->getMessage();

    echo
sprintf("Error happened: %s", $errorMessage);
}

echo
PHP_EOL;