<?php
 
/**
 
 * Google_TTS (Google's Text-to-Speech System) Class example
 
 *
 
 * @author Mahmut Namli <[email protected]>
 
 */
 
 
header('Content-Type: text/html; charset=UTF-8');
 
ini_set('error_reporting', -1);
 
 
/* Taking unique timestamp for file names */
 
$timestamp = time();
 
 
/* Firstly, I need to integrate the class file for example.. */
 
require_once 'google.tts.php';
 
 
/* Instantiate the class */
 
$ttsObj = new Google_TTS();
 
 
/* Make a decision for spoofing IP address for CURL REMOTE_ADDR and HTTP_X_FORWARDED_FOR
 
 * default is 'random'
 
 */
 
$ttsObj->headerIP("random");
 
 
/* object needs the text's language and the text's self which will be converted to mp3 files as speech
 
 * 
 
 * Note 1: as of this is a free service, you're limited to 100 characters of the text hence using $_GET
 
 * Note 2: Languages generally 2 chars of localcodes, you can find them in the $ttsObj->languages variable.
 
 */
 
$ttsObj->text( $_GET['lang'], $_GET['word'] );
 
 
/* I'm taking the first 20 character of word for filename.. */
 
$wordForFileName = substr($_GET['word'], 0, 20);
 
 
/* let's output as audio on browser directly */
 
$ttsObj->speakIt('direct');
 
 
/* of course if I need a file of soundData, just telling the where to saving it: */
 
$ttsObj->speakIt("spoken_sentences/{$timestamp}_{$wordForFileName}.mp3");
 
 
 |