2

hi iam using this code to post the url and get result but its adding =0 before every result

my code is

    <!DOCTYPE HTML>
<html>
<body>
<h1>In this demonstration:<br />
>tts is done on server side (i.e by using Google-translate server)<br/>
>then the audio received from Google-translate server is saved on your server (local/production)<br />
>and then that saved audio is played through that saved file on this webpage.</h1>
<h3>
Tested with:
Chrome v21 [Working],
Firefox v14 [Not Working, firefox does not support mp3 audio format playback],
IE v9[Working]
</h3>
<hr />
<form method="POST">
Text to convert : <input name="txt" type="text" /><br />
Filename to save (without the extension) : <input name="filename" type="text" /><br />
Convert text to speech : <input name="submit" type="submit" value="Convert" />
</form>

<?php
if (isset($_POST['txt']) && isset($_POST['filename']))
{
    $text=htmlentities($_POST['txt']);
    $filename=$_POST['filename'].'.mp3';

    $querystring = http_build_query(array($text));

    if ($soundfile = file_get_contents("http://api.voicerss.org?key=c68635f1104b452e8dbe740c0c0330f3&src=$querystring&hl=en-in j"))
    {
        file_put_contents($filename,$soundfile);
        echo ('
            <audio autoplay="autoplay" controls="controls">
            <source src="'.$filename.'" type="audio/mp3" />
            </audio>
            <br />
            Saved mp3 location : '.dirname(__FILE__).'\\'.$filename.'
            <br />
            Saved mp3 uri : <a href="'.$filename.'">'.$_SERVER['SERVER_NAME'].'/webtts/'.$filename.'</a>'
        );
    }
    else echo("<br />Audio could not be saved");
}
?>

Its result is http://api.voicerss.org?key=c68635f1104b452e8dbe740c0c0330f3&src=0=Good+evening.+Please+sit+down.+Now+tell+me+about+your+problem&hl=en-in

It should not show src=0=Good, it should show src=Good+evening, how to remove 0=

1 Answer 1

6

You need to supply an associative array to http_build_query

So change

 http_build_query(array($text))

to

 http_build_query(array("src"=>$text))

and

 file_get_contents("http://api.voicerss.org?key=c68635f1104b452e8dbe740c0c0330f3&src=$querystring&hl=en-in j

to

file_get_contents("http://api.voicerss.org?key=c68635f1104b452e8dbe740c0c0330f3&$querystring&hl=en-in j

Alternatively you can use

http_build_query(array(
     "src"=>$text,
     "key"=>"c68635f1104b452e8dbe740c0c0330f3",
     "hl"=>"en-in j"))

and

file_get_contents("http://api.voicerss.org?".$querystring);
Sign up to request clarification or add additional context in comments.

1 Comment

@ShiveshJaiswal If you found this answer to be helpful click the check by the answer title to accept it and close out the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.