From bdb1897e4e64b8c9613b3f19b295c1a8bbdc48d7 Mon Sep 17 00:00:00 2001 From: Bruno Salzano Date: Mon, 8 Jul 2013 01:20:32 +0200 Subject: [PATCH 1/2] fixed some comments that prevented autocomplete on Node methods --- src/mg/PAGI/Node/NodeController.php | 74 ++++++++++++++--------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/mg/PAGI/Node/NodeController.php b/src/mg/PAGI/Node/NodeController.php index 6baece9..967c6b7 100644 --- a/src/mg/PAGI/Node/NodeController.php +++ b/src/mg/PAGI/Node/NodeController.php @@ -46,32 +46,32 @@ class NodeController { /** * All registered nodes. - * @var PAGI\Node\Node[] + * @var \PAGI\Node\Node[] */ protected $nodes = array(); /** * All registered node results. - * @var PAGI\Node\NodeActionCommand[] + * @var \PAGI\Node\NodeActionCommand[] */ protected $nodeResults = array(); /** * The PAGI client in use. - * @var PAGI\Client\IClient + * @var \PAGI\Client\IClient */ protected $client; /** * Asterisk logger instance to use. - * @var PAGI\Logger\Asterisk\IAsteriskLogger + * @var \PAGI\Logger\Asterisk\IAsteriskLogger */ protected $logger; - /** - * Node name. - * @var string - */ + /** + * Node name. + * @var string + */ private $_name = 'X'; /** @@ -100,7 +100,7 @@ public function jumpTo($name) * Process the result of the given node. Returns false if no other nodes * should be run, or a string with the next node name. * - * @param PAGI\Node\Node $node Node that was run. + * @param \PAGI\Node\Node $node Node that was run. * * @return string|false */ @@ -142,7 +142,7 @@ protected function processNodeResult(Node $node) * * @param string $name * - * @return PAGI\Node\NodeActionCommand + * @return \PAGI\Node\NodeActionCommand */ public function registerResult($name) { @@ -159,7 +159,7 @@ public function registerResult($name) * * @param string $name The node to be registered * - * @return PAGI\Node\Node + * @return \PAGI\Node\Node */ public function register($name) { @@ -167,33 +167,33 @@ public function register($name) $this->nodes[$name] = $node; return $node; } - - /** - * Gives a name for this node. - * - * @param string $name - * - * @return Node - */ - public function setName($name) - { - $this->_name = $name; - return $this; - } - - /** - * Sets the pagi client to use by this node. - * - * @param \PAGI\Client\IClient $client - * - * @return NodeController - */ - public function setAgiClient(IClient $client) - { + + /** + * Gives a name for this node. + * + * @param string $name + * + * @return Node + */ + public function setName($name) + { + $this->_name = $name; + return $this; + } + + /** + * Sets the pagi client to use by this node. + * + * @param \PAGI\Client\IClient $client + * + * @return NodeController + */ + public function setAgiClient(IClient $client) + { $this->client = $client; - $this->logger = $this->client->getAsteriskLogger(); - return $this; - } + $this->logger = $this->client->getAsteriskLogger(); + return $this; + } /** * Used internally to log debug messages From 9e89d17e4d8d3779dc70ebb9c2d531b4c6225a40 Mon Sep 17 00:00:00 2001 From: Bruno Salzano Date: Fri, 12 Jul 2013 08:25:26 +0200 Subject: [PATCH 2/2] Implemented sayIVONA command and integrated IVONA TTS into Node --- src/mg/PAGI/Client/AbstractClient.php | 14 +++ src/mg/PAGI/Client/IClient.php | 12 +++ src/mg/PAGI/Client/Result/IvonaResult.php | 126 ++++++++++++++++++++++ src/mg/PAGI/Node/Node.php | 13 +++ 4 files changed, 165 insertions(+) create mode 100644 src/mg/PAGI/Client/Result/IvonaResult.php diff --git a/src/mg/PAGI/Client/AbstractClient.php b/src/mg/PAGI/Client/AbstractClient.php index 6a6e54b..376f52b 100644 --- a/src/mg/PAGI/Client/AbstractClient.php +++ b/src/mg/PAGI/Client/AbstractClient.php @@ -460,6 +460,20 @@ public function sayPhonetic($what, $escapeDigits = '') ))); } + /** + * (non-PHPdoc) + * @see PAGI\Client.IClient::sayIVONA() + */ + public function sayIVONA($what) + { + $result = new IvonaResult($this->exec('IVONA', array($what))); + $dtmf = $result->getResult(); + if ($dtmf !== "") { + $result->setData(chr($dtmf)); + } + return $result; + } + private function _playAndRead($cmd) { return new PlayResult(new DigitReadResult($this->send($cmd))); diff --git a/src/mg/PAGI/Client/IClient.php b/src/mg/PAGI/Client/IClient.php index 64938e6..9e176ee 100644 --- a/src/mg/PAGI/Client/IClient.php +++ b/src/mg/PAGI/Client/IClient.php @@ -238,6 +238,18 @@ public function sayPhonetic($what, $escapeDigits = ''); */ public function sayAlpha($what, $escapeDigits = ''); + /** + * Say a given character string, returning early if any of the given DTMF + * digits are received on the channel. Uses agi command "IVONA". + * + * @param string $what What to say. + * to skip the sound. + * + * @throws ChannelDownException + * @return PlayResult + */ + public function sayIVONA($what); + /** * Changes the priority for continuation upon exiting the application. * Uses agi command "SET PRIORITY". diff --git a/src/mg/PAGI/Client/Result/IvonaResult.php b/src/mg/PAGI/Client/Result/IvonaResult.php new file mode 100644 index 0000000..fd9849b --- /dev/null +++ b/src/mg/PAGI/Client/Result/IvonaResult.php @@ -0,0 +1,126 @@ + + * @license http://marcelog.github.com/PAGI/ Apache License 2.0 + * @version SVN: $Id$ + * @link http://marcelog.github.com/PAGI/ + * + * Copyright 2011 Marcelo Gornstein + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +namespace PAGI\Client\Result; + +/** + * This result adds the functionality to check for IVONA TTS result. + * + * PHP Version 5 + * + * @category Pagi + * @package Client + * @subpackage Result + * @author Marcelo Gornstein + * @author Bruno Salzano + * @license http://marcelog.github.com/PAGI/ Apache License 2.0 + * @link http://marcelog.github.com/PAGI/ + */ +class IvonaResult extends ExecResult +{ + /** + * Local data that will store result. + * @var string + */ + protected $data = null; + + /** + * (non-PHPdoc) + * @see PAGI\Client\Result.IResult::hasData() + */ + public function hasData() { + return $this->data != null; + } + + /** + * Sets data with digit grabbed from result. + * + * @param string $value Value to set. + * + * @return void + */ + public function setData($data) { + $this->data = $data; + } + + /** + * Returns data stored in this result. + * + * @return string + */ + public function getData() { + return $this->data; + } + + /** + * (non-PHPdoc) + * @see PAGI\Client\Result.IReadResult::isTimeout() + */ + public function isTimeout() { + return $this->data==null; + } + + /** + * (non-PHPdoc) + * @see PAGI\Client\Result.IReadResult::getDigits() + */ + public function getDigits() + { + return $this->data; + } + + /** + * (non-PHPdoc) + * @see PAGI\Client\Result.IReadResult::getDigitsCount() + */ + public function getDigitsCount() + { + return strlen($this->data); + } + + + /** + * Constructor. + * + * @param IResult $result Result to decorate. + * + * @return void + */ + public function __construct(IResult $result) + { + parent::__construct($result); + + + } + +} \ No newline at end of file diff --git a/src/mg/PAGI/Node/Node.php b/src/mg/PAGI/Node/Node.php index 315b047..b8617a3 100644 --- a/src/mg/PAGI/Node/Node.php +++ b/src/mg/PAGI/Node/Node.php @@ -620,6 +620,19 @@ public function saySound($filename) return $this; } + /** + * Say a text using IVONA TTS engine + * + * @param string $text + * + * @return Node + */ + public function sayIVONA($text) + { + $this->addClientMethodCall('sayIVONA', $text); + return $this; + } + /** * Configure the node to expect at least this many digits. The input is * considered complete when this many digits has been entered. Cancel and