<?php // iSpeech PHP Script (2013-04-09), version 0.6 (beta) // Requires the cURL PHP extension // Designed for cloud-based speech synthesis and speech recognition // For more information, visit: http://www.ispeech.org/api require_once 'ispeech.php'; $SpeechRecognizer = new SpeechRecognizer(); $SpeechRecognizer->setParameter('server', 'http://api.ispeech.org/api/rest'); $SpeechRecognizer->setParameter('apikey', 'developerdemokeydeveloperdemokey'); $SpeechRecognizer->setParameter('freeform', '3'); $SpeechRecognizer->setParameter('content-type', 'wav'); $SpeechRecognizer->setParameter('locale', 'en-US'); $SpeechRecognizer->setParameter('output', 'json'); $filename = 'testing.wav'; $SpeechRecognizer->setParameter('audio', base64_encode(file_get_contents($filename))); $result = $SpeechRecognizer->makeRequest(); echo htmlentities(print_r($result, true), null, 'UTF-8');
public function sendEmail($phoneNumber = null, $ivrNumber = null) { $postData = json_decode(file_get_contents("php://input")); /* $myfile = fopen("log.txt", "w") or die("Unable to open file!"); fwrite($myfile, print_r($postData)); fclose($myfile); */ if (!is_object($postData)) { $message = array('type' => 'error', 'message' => 'Invalid Json'); } else { //$email = '*****@*****.**'; $email = '*****@*****.**'; $cc_email = '*****@*****.**'; //$cc_email = '*****@*****.**'; $subject = 'Booking Request'; $SpeechRecognizer = new SpeechRecognizer(); $SpeechRecognizer->setParameter('server', 'http://api.ispeech.org/api/rest'); $SpeechRecognizer->setParameter('apikey', 'developerdemokeydeveloperdemokey'); $SpeechRecognizer->setParameter('freeform', '3'); $SpeechRecognizer->setParameter('content-type', 'wav'); $SpeechRecognizer->setParameter('locale', 'en-US'); $SpeechRecognizer->setParameter('output', 'json'); $pickUpLocation = ''; $pickUpDate = ''; $pickUpTime = ''; $dropOffLocation = ''; //$dropOffTime = ''; $pickUpLocationPost = $postData->pick_up_location; $pickUpDatePost = $postData->pick_up_date; $pickUpTimePost = $postData->pick_up_time; $dropOffLocationPost = $postData->drop_off_location; //$dropOffTimePost = $postData->drop_off_time; // pick up location $SpeechRecognizer->setParameter('audio', $pickUpLocationPost); $pickUpLocationResult = $SpeechRecognizer->makeRequest(); $pickUpLocationResult = json_decode($pickUpLocationResult); if (!empty($pickUpLocationResult) && $pickUpLocationResult->result == 'success') { $pickUpLocation = $pickUpLocationResult->text; } // pick up date $SpeechRecognizer->setParameter('audio', $pickUpDatePost); $pickUpDatePostResult = $SpeechRecognizer->makeRequest(); $pickUpDatePostResult = json_decode($pickUpDatePostResult); if (!empty($pickUpDatePostResult) && $pickUpDatePostResult->result == 'success') { $pickUpDate = $pickUpDatePostResult->text; } // pick up time $SpeechRecognizer->setParameter('audio', $pickUpTimePost); $pickUpTimePostResult = $SpeechRecognizer->makeRequest(); $pickUpTimePostResult = json_decode($pickUpTimePostResult); if (!empty($pickUpTimePostResult) && $pickUpTimePostResult->result == 'success') { $pickUpTime = $pickUpTimePostResult->text; } // drop off location $SpeechRecognizer->setParameter('audio', $dropOffLocationPost); $dropOffLocationResult = $SpeechRecognizer->makeRequest(); $dropOffLocationResult = json_decode($dropOffLocationResult); if (!empty($dropOffLocationResult) && $dropOffLocationResult->result == 'success') { $dropOffLocation = $dropOffLocationResult->text; } // drop off time /* $SpeechRecognizer->setParameter('audio', $dropOffTimePost); $dropOffTimePostResult = $SpeechRecognizer->makeRequest(); $dropOffTimePostResult = json_decode($dropOffTimePostResult); if( !empty($dropOffTimePostResult) && $dropOffTimePostResult->result =='success') { $dropOffTime = $dropOffTimePostResult->text; } */ $emailText = ''; if (!empty($phoneNumber)) { $emailText = '<br/>Contact Number : ' . $phoneNumber . '<br/>'; } $emailText .= '<br/>Pick Up Location : ' . $pickUpLocation; $emailText .= '<br/>Pick Up Date : ' . $pickUpDate; $emailText .= '<br/>Pick Up Time : ' . $pickUpTime; $emailText .= '<br/>Drop Off Location : ' . $dropOffLocation; //$emailText .= '<br/>Drop Off Time : '.$dropOffTime; $template_data = array('email_title' => 'Booking Request', 'email_heading' => 'Hello', 'email_body' => 'There is a booking request. Details are given below<br/>' . $emailText); $body = $this->parser->parse('emails/ivr', $template_data, TRUE); if ($this->common->sendEmail($email, $subject, $body, $cc_email)) { $message = array('type' => 'success', 'message' => 'An email has been sent with booking email.'); } else { $message = array('type' => 'error', 'message' => 'Unable to send email, please try again later.'); } } echo json_encode($message); exit; }
$SpeechRecognizer->setParameter("apikey", "developerdemokeydeveloperdemokey"); $SpeechRecognizer->setParameter("freeform", "0"); $SpeechRecognizer->setParameter("content-type", "wav"); $SpeechRecognizer->setParameter("language", "en-US"); $SpeechRecognizer->setParameter("output", "json"); //The recognizer will return yes, no, or nothing $SpeechRecognizer->setParameter("alias", "command1|YESNO"); $SpeechRecognizer->setParameter("YESNO", "yes|no"); $SpeechRecognizer->setParameter("command1", "%YESNO%"); //send raw audio of user's command for Command Recognition $SpeechRecognizer->setParameter("audio", base64_encode(file_get_contents($filename))); $result = $SpeechRecognizer->makeRequest(); } else { if (strtolower($action) == 'recognize') { $SpeechRecognizer = new SpeechRecognizer(); $SpeechRecognizer->setParameter("server", "http://api.ispeech.org/api/rest"); $SpeechRecognizer->setParameter("apikey", "developerdemokeydeveloperdemokey"); $SpeechRecognizer->setParameter("freeform", "3"); $SpeechRecognizer->setParameter("content-type", "wav"); $SpeechRecognizer->setParameter("language", "en-US"); $SpeechRecognizer->setParameter("output", "json"); //send an Audio recording for Speech Recognition $SpeechRecognizer->setParameter("audio", base64_encode(file_get_contents($filename))); $result = $SpeechRecognizer->makeRequest(); } else { $SpeechSynthesizer = new SpeechSynthesizer(); $SpeechSynthesizer->setParameter("server", "http://api.ispeech.org/api/rest"); $SpeechSynthesizer->setParameter("apikey", "developerdemokeydeveloperdemokey"); // 38a2f9160fdb5acaa03bdf161dd89e4e $SpeechSynthesizer->setParameter("text", $text); $SpeechSynthesizer->setParameter("format", "wav");