<?php

require_once '../source/Catapult.php';
// below is a sample of Catapult BaML
// it will execute the provided verb
// IMPORTANT: edit credentials.json
// with your information
// or comment out below /w your keys
//
//$cred = new Catapult\Credentials('BANDWIDTH_USER_ID', 'BANDWIDTH_API_TOKEN', 'BANDWIDTH_API_SECRET');
$cred = new Catapult\Credentials();
// dont forget to comment out the implicit version if using assoc array
// this example is cli based
$client = new Catapult\Client($cred);
// generates objects from the BaML string
try {
    $baml = new Catapult\BaML();
    $baml->parse("\n<Request>\n    <SpeakSentence voice=\"male\" locale=\"en\">Hello Example</SpeakSentence>\n    <Redirect requestUrl=\"http://example.org\">Redirect</Redirect>\n</Request>\n    ");
    printf("generated the following BaML objects\n");
    foreach ($baml->getVerbs() as $verb) {
        printf("Verb: %s was generated with attributes (%s) and text: (%s)\n", $verb->getName(), $verb->getAttributesString(), $verb->getText());
    }
} catch (\CatapultApiException $e) {
    echo var_dump($e);
}
Beispiel #2
0
// IMPORTANT: edit credentials.json
// with your information
// or comment out below /w your keys
//
//$cred = new Catapult\Credentials('BANDWIDTH_USER_ID', 'BANDWIDTH_API_TOKEN', 'BANDWIDTH_API_SECRET');
$cred = new Catapult\Credentials();
// dont forget to comment out the implicit version if using assoc array
// this example is cli based
// use like:
// php ./sample-baml.php "verb" "attribute" "value"
// example
// php ./sample-baml.php "SpeakSentence" "voice" "female"
$client = new Catapult\Client($cred);
if (!(isset($argv[1]) || isset($argv[2]) || isset($argv[3]))) {
    die("\nPlease provide command line input like: \n php ./sample-verb.php 'verb' 'attribute' 'value'\n\n");
}
try {
    $verb = $argv[1];
    $attribute = $argv[2];
    $value = $argv[3];
    $baml = new Catapult\BaML();
    $bverb = Catapult\BaMLVerb::fromString($verb);
    $bverb->create(array(new Catapult\BaMLAttribute($attribute, $value)));
    // here we can add other things
    // verbs, attributes or text
    $bverb->addText("example");
    $baml->set($bverb);
    printf("The following BaML was generated: \n\n%s\n\n", $baml);
} catch (\CatapultApiException $e) {
    echo var_dump($e);
}
<?php

require_once "../source/Catapult.php";
// below is a sample of Catapult of joining
// multiple BaML verbs.
//
// This example uses 0.7.0
// please note Credentials object is not here
// and does not need to be used anymore
$client = new Catapult\Client();
$baml = new Catapult\BaML();
$gatherVerb = new Catapult\BaMLGather();
$speakSentenceVerb = new Catapult\BaMLSpeakSentence();
$gatherVerb->addAttribute("terminatingDigits", "#");
$gatherVerb->addAttribute("maxDigits", "10");
$speakSentenceVerb->addText("Hello this is just an example.");
// this will nest one verb in another
$gatherVerb->addVerb($speakSentenceVerb);
// we can also directly edit the nested
// verb using gatherVerb!
$playAudio = new Catapult\BaMLPlayAudio();
$gatherVerb->addNestedVerb(0, $playAudio);
// remember to add the verb in our root container
// verbs need one root verb.
$baml->set($gatherVerb);
// lets dump our container
echo var_dump($baml);
Beispiel #4
0
 public function testFromFile()
 {
     $baml = new Catapult\BaML();
     $baml->getAsStream(__BAML_UNIT_TEST_FILE_LOCATION__);
 }