Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ivona #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/mg/PAGI/Client/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,20 @@ public function sayPhonetic($what, $escapeDigits = '')
)));
}

/**
* (non-PHPdoc)
* @see PAGI\Client.IClient::sayIVONA()
*/
public function sayIVONA($what)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's call this sayIvona

{
$result = new IvonaResult($this->exec('IVONA', array($what)));
$dtmf = $result->getResult();
if ($dtmf !== "") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use empty() here

$result->setData(chr($dtmf));
}
return $result;
}

private function _playAndRead($cmd)
{
return new PlayResult(new DigitReadResult($this->send($cmd)));
Expand Down
12 changes: 12 additions & 0 deletions src/mg/PAGI/Client/IClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
126 changes: 126 additions & 0 deletions src/mg/PAGI/Client/Result/IvonaResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php
/**
* This decorated result adds the functionality to check for user input. We
* need a distinction between a single digit read (this class) and a data read
* (DataReadResult) because asterisk sends the ascii number for the character
* read (the first case) and the literal string in the latter.
*
* PHP Version 5
*
* @category Pagi
* @package Client
* @subpackage Result
* @author Marcelo Gornstein <[email protected]>
* @license http://marcelog.github.com/PAGI/ Apache License 2.0
* @version SVN: $Id$
* @link http://marcelog.github.com/PAGI/
*
* Copyright 2011 Marcelo Gornstein <[email protected]>
*
* 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 <[email protected]>
* @author Bruno Salzano <[email protected]>
* @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);


}

}
13 changes: 13 additions & 0 deletions src/mg/PAGI/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 37 additions & 37 deletions src/mg/PAGI/Node/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -142,7 +142,7 @@ protected function processNodeResult(Node $node)
*
* @param string $name
*
* @return PAGI\Node\NodeActionCommand
* @return \PAGI\Node\NodeActionCommand
*/
public function registerResult($name)
{
Expand All @@ -159,41 +159,41 @@ public function registerResult($name)
*
* @param string $name The node to be registered
*
* @return PAGI\Node\Node
* @return \PAGI\Node\Node
*/
public function register($name)
{
$node = $this->client->createNode($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
Expand Down