Login   Register  
PHP Classes
elePHPant
Icontem

File: tts/sound.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mahmut Namli  >  PHP Google Text to Speech  >  tts/sound.php  >  Download  
File: tts/sound.php
Role: Application script
Content type: text/plain
Description: Google TTS helper file
Class: PHP Google Text to Speech
Convert words to voice using Google Translate API
Author: By
Last change: 1) File destination edited
Date: 2014-01-17 16:15
Size: 1,334 bytes
 

Contents

Class file image Download
<?php
/**
 * Google_TTS (Google's Text-to-Speech System) Class example
 *
 * @author Mahmut Namli <mahmudnamli@gmail.com>
 */

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'], 020);

/* 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");