php - Add Google TTS for a Script which works on several browsers -



php - Add Google TTS for a Script which works on several browsers -

with help have ajax-function, instantly react on input-value. (change submit-button ajax-function instantly reacting input)

this function display word of entered number in russian. want add together left word play icon pronunciate out word click on it.

i found solution google tts (text-to-speech), in examples works in google chrome. ie , firefox (newest versions) doens't work.

another problem: 1. function allows maximum 100 characters pronunciate, script should splits big inputs (>100 chars) multiple consecutive requests exampel biggest possible number 999999999999999.

as continuation, since ajax (the normal processes) working implement same way did on test site. consider example:

<form method="post" action="index.php"> <label for="zahl">zahl:</label> <br/> <input id="zahl" name="zahl" type="number" size="15" maxlength="15"><br/><br/> <img src="http://lern-online.net/bilder/symbole/play.png" id="playsound" style="display: none; " /> <span id="results" style="width: 400px;"></span> <!-- results appear here --> </form> <div class="player"></div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <!-- <script src="jquery.min.js"></script> --> <script type="text/javascript"> $(document).ready(function(){ $('#zahl').on('keyup', function(){ var input = $(this).val(); if(input != '') { // ajax request server $.ajax({ url: 'index.php', type: 'post', datatype: 'text', data: {value: input}, success: function(response) { $('#results').text(response); // append result div $('#playsound').show(); } }); } else { $('#results').text(''); $('#playsound').hide(); } }); // add together this, since spawns new embed tags every click $('#playsound').click(function(){ var input = encodeuricomponent($('#results').text()); $('.player').html('<audio controls="" autoplay="" name="media" hidden="true" autostart><source src="sound.php?text='+input+'" type="audio/mpeg"></audio>'); }); }); </script>

create new php file handle sound requests:

call sound.php

<?php $txt = $_get['text']; $txt = urlencode($txt); header("content-type: audio/mpeg"); $url ="http://translate.google.com/translate_tts?q=$txt&tl=ru&ie=utf-8"; $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_timeout, 30); $audio = curl_exec($ch); echo $audio; ?>

php jquery google-text-to-speech

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -