IT Community - Software Programming, Web Development and Technical Support

Convert Text to Speech

This is a discussion on Convert Text to Speech within the PHP Programming forums, part of the Web Development category; Hi. This is the simple program for converting the text to speech in php. this is the class file with ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 09-05-2007, 03:12 AM
saravanan saravanan is offline
D-Web Sr.Programmer
 
Join Date: Jul 2007
Posts: 181
saravanan is on a distinguished road
Thumbs up Convert Text to Speech

Hi.
This is the simple program for converting the text to speech in php.

this is the class file with the name texttospeech.php file
Enter the coding
----- --- ------

<?php
class s_TS
{
var $txt = '';
var $bufor = '';
var $error = 0;
var $error_file = 'error.audio';

function s_TS ($text, $language="eng", $limit=390)
{
/******************************/

$limit = ($limit > 390) ? 390 : $limit;
$this->txt = @substr(trim(strip_tags($text)), 0, $limit);
$this->txt .= ' ';

/*****************************/
switch ($language)
{
case 'eng':
$lang = 'Angielski';
break;
case 'pl':
$lang = 'Polski';
break;
default:
$lang = 'Angielski';
break;
}

for ($c=0; $c<strlen($this->txt); $c+=0)
{
$zajawka = &$this->zajawka($this->txt, $c);
$num_z = strlen($zajawka);
if ($num_z == 0)
{
break;
if ($c == 0)
{
$this->error = 1;
}
}

for ($i=0; $i < 2; $i++)
{
$kod = &$this->codeweb ('http://www.expressivo.com/pl/ivonaonline.html',
array("\n", "\r", "\t"),
array("", "", ""),
"P",
"flashdet=&allowScriptAccess=sameDomain&tresc=".ur lencode($zajawka)."&znak=200&IVONA_odczytaj=1&glos =".$lang
);
}

@preg_match_all('/<a.*?href="http:\/\/www.expressivo.com\/pl\/media\/ivonaonline\/([a-zA-Z0-9]+).mp3".*?>(.*?)<\/a>/i', $kod, $linki);

if ($linki[2][0] == '')
{
$this->error = 1;
break;
}
else
{
$file_mp3[] = $linki[2][0];
}
$c += $num_z;
}

if (@is_array($file_mp3))
{
foreach ($file_mp3 as $url)
{
if ($s = @fopen($url, "rb"))
{
while (!feof($s))
{
$this->bufor .= @fread($s,1024);
}
@fclose($s);
}
else
{
$this->error = 1;
}
}
}
else
{
$this->error = 1;
}
}

function print_bufor ()
{
/***/
if ($this->error == 1)
{
if ($s = @fopen($this->error_file, "rb"))
{
while (!feof($s))
{
$this->bufor .= @fread($s,1024);
}
@fclose($s);
}
}
return $this->bufor;
/***/
}

function codeweb ($url, $tag1="", $tag2="", $tryb="GET", $post="")
{
/***/
$ch = @curl_init();
if ($tryb != "GET")
{
@curl_setopt($ch, CURLOPT_POST, 1);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
@curl_setopt($ch, CURLOPT_URL, $url);
@curl_setopt($ch, CURLOPT_HEADER, 0);
@curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = @curl_exec($ch);
if (@is_array($tag1) && @is_array($tag2))
{
$data = str_replace($tag1, $tag2, $data);
}
if ($data == '') {return false;}
return $data;
/***/
}

function zajawka ($t, $o=0, $l=200)
{
/***/
if (strlen($t) > $l)
{
$t = preg_replace("/\s+(\S+)?$/", "", substr($t, $o, $l));
}
return $t;
/***/
}
}
?>


create the file with name example_speech.php

<?php
header("Content-type: audio/mpeg");
header("Content-Disposition: attachment; filename=\"test.mp3\"");
include('texttospeech.php');
/* max length 390 signs */
$text = 'hello how are You, i am fine.';
$s_ts = &new s_TS($text, 'eng');
echo $s_ts->print_bufor();
?>

Run the example_speech.php file means do u hear the speech that do u have entered.


Thanks
T.Saravanan.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-05-2007, 07:08 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: Convert Text to Speech

Wow..Its nice one.
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/php-programming/3624-convert-text-speech.html
Posted By For Type Date
programming: Blogs, Photos, Videos and more on Technorati This thread Refback 09-05-2007 03:53 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
convert a text string into a Date object. itbarota HTML, CSS and Javascript Coding Techniques 2 02-12-2008 06:37 AM
How do I check that text entered in a text form field is an integer? itbarota HTML, CSS and Javascript Coding Techniques 2 10-26-2007 12:25 AM
convert Excel file to CSV(or text) file using java mobilegeek Java Programming 2 09-06-2007 06:42 AM
How to Encode a text and Decode it to get the original text using c# .Net? Archer C# Programming 1 07-21-2007 01:10 AM
How to convert a word document/text document/PDF file into an image file? kingmaker C# Programming 0 07-16-2007 11:23 PM


All times are GMT -7. The time now is 03:10 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0