Speed up development with full-stack environments for every branch.

Learn More

How to enable Client (browser) to Speech Text [PHP, twilio and jQuery]

283 Runs 1509 Views 206 Copies
Saved

Saved

dipesh.parmar 55

dipesh.parmar
published 4 years ago

<?php
// @start snippet
require_once('twilio-php-master/Services/Twilio/Capability.php');

$ACCOUNT_SID = getenv("SID");
$AUTH_TOKEN  = getenv("TOKEN");
$APP_SID     = "AP515f53584aa1875dc386bc83db65f90a";//replace this with your app_sid

$token = new Services_Twilio_Capability($ACCOUNT_SID, $AUTH_TOKEN);
$token->allowClientOutgoing($APP_SID);
// @end snippet
?>
<!DOCTYPE HTML>
<html> 
  <head> 
  	<title>TTS Tester</title> 
		<!-- @start snippet -->
		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> 
		<script type="text/javascript" src="http://static.twilio.com/libs/twiliojs/1.1/twilio.min.js"></script>
 
		<script type="text/javascript"> 
 
 			Twilio.Device.setup("<?php echo $token->generateToken();?>",{"debug":true});

			$(document).ready(function() {
				$("#submit").click(function() {
          //calling speak function.
          //by calling this function we will send selected user input
          // to twilio using javascript.
					speak();
				});
			});
 
			function speak()
      {
				var dialogue = $("#dialogue").val();
				var voice = $('input:radio[name=voice]:checked').val();
 
				$('#submit').attr('disabled', 'disabled');
 
				Twilio.Device.connect({ 'dialogue' : dialogue, 'voice' : voice });
			}
 
			Twilio.Device.disconnect(function (conn) {
				$('#submit').removeAttr('disabled');
			});
			<!-- @end snippet -->
		</script> 
	</head> 
	<body> 
		<!-- @start snippet -->
		<p> 
			<label for="dialogue">Text to be spoken</label> 
			<input type="text" id="dialogue" name="dialogue" size="50"> 
		</p> 
		<p> 
			<label for="voice-male">Male Voice</label> 
			<input type="radio" id="voice-male" name="voice" value="1" checked="checked"> 
			<label for="voice-female">Female Voice</label> 
			<input type="radio" id="voice-female" name="voice" value="2"> 
		</p> 
		<p> 
			<input type="button" id="submit" name="submit" value="Speak to me"> 
		</p> 
		<!-- @end snippet-->
    
    <h3>Example is running. Call <? echo getenv('TWILIO_NUMBER');?></h3>
    <p>Some additional steps may need to be completed first.
     More information can be found 
     <a target="_blank" href="https://www.twilio.com/docs/howto/twilio-client-text-to-speech">here</a>.</p>
     
    <ol>
      <li>Login to your Twilio account 
          (<a target="_blank" href="https://twilio.com/login">twilio.com/login</a>)</li>
      <li>Click on "Numbers" and select your Twilio number</li>
      <li>Update the Voice Request URL with this example's URL: 
          <? echo getenv('BASE_URL');?>/incoming_call.php</li> 
      <li>You should be ready to call the number and test out this example.</li>
    </ol>
      
	</body> 
</html>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).