text to speect AZURE add silence - php

Hi I'm trying to add a pause in the text to speech Azure api, this code works fine but I can't add silence. I need to add silence when a specific character is found in the text, I tried with or <mstts:ttsbreak strength="none" /> but the audio output speech the tags instead to make a pause.
$doc = new DOMDocument();
$root = $doc->createElement( "speak" );
$root->setAttribute( "xmlns" , "http://www.w3.org/2001/10/synthesis" );
$root->setAttribute( "xmlns:mstts" , "http://www.w3.org/2001/mstts" );
$root->setAttribute( "xmlns:emo" , "http://www.w3.org/2009/10/emotionml" );
$root->setAttribute( "version" , "1.0" );
$root->setAttribute( "xml:lang" , "$spechlang" );
$voice = $doc->createElement( "voice" );
$voice->setAttribute( "name" , "$myvoice");
$style = $doc->createElement( "mstts:express-as" );
$style->setAttribute( "style" , "whispering"); //
$prosody = $doc->createElement( "prosody" );
$prosody->setAttribute( "rate" , "$rate.00%" );
$prosody->setAttribute( "pitch" , "$pitch.00%" );
$text = $doc->createTextNode( "$mytext" );
$prosody->appendChild( $text );
$style->appendChild( $prosody );
$voice->appendChild( $style );
$root->appendChild( $voice );
$doc->appendChild( $root );
$data = $doc->saveXML();
$options = array(
'http' => array(
'header' => "Content-type: application/ssml+xml\r\n" .
"X-Microsoft-OutputFormat: riff-24khz-16bit-mono-pcm\r\n" .
"Authorization: "."Bearer ".$access_token."\r\n" .
"X-Search-AppId: 07D3234E56TT426DAA29772419F436CA\r\n" .
"X-Search-ClientID: 1ECFAE91406677A480F00935DC390960\r\n" .
"User-Agent: TTSPHP\r\n" .
"content-length: ".strlen($data)."\r\n",
'method' => 'POST',
'content' => $data,
),
);
$context = stream_context_create($options);
// get the wave data
$result = file_get_contents($ttsServiceUri, false, $context);
a ssml generated could be
<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="it-IT">
<voice name="en-US-JennyNeural">
1. first point: <break strength="medium" />
lore lipso bla bla.
</voice></speak>
this SSML work fine on https://speech.microsoft.com/portal SPEECH STUDIO PORTAL but not in my php. thanks

Related

404 Error connecting to the API (https://developer.api.autodesk.com/modelderivative/v2/designdata/job) when i use php-client-forge autodesk api

i want to use the autodesk forge viewer api in my php application in order to view ifc files so i used the forge-php-client sdk.everything works fine but the translating job doesn't and i'm getting this error : [404] Error connecting to the API (https://developer.api.autodesk.com/modelderivative/v2/designdata/job
here the code:
/step1
Configuration::getDefaultConfiguration()
->setClientId('xxxxxxxxxxxxxxxxxxxxxx')
->setClientSecret('xxxxxxxxxxxxxxxxxx');
$twoLeggedAuth = new TwoLeggedAuth();
$twoLeggedAuth->setScopes( [ 'bucket:create' ] );
$twoLeggedAuth->fetchToken();
$tokenInfo = [
'accessToken' => $twoLeggedAuth->getAccessToken(),
'expiry' => time() + $twoLeggedAuth->getExpiresIn(),
];
//step2
$twoLeggedAuth->setScopes( [ 'bucket:create' ] );
$twoLeggedAuth->fetchToken();
$apiInstance = new BucketsApi( $twoLeggedAuth );
$bucket_info = array(
'bucket_key' => 'nebnibim5'.time(),
'policy_key' => 'transient'
);
$post_buckets = new PostBucketsPayload( $bucket_info );
$result = $apiInstance->createBucket( $post_buckets, null );
$twoLeggedAuth = new TwoLeggedAuth();
$twoLeggedAuth->setScopes( [ 'data:write' ] );
$twoLeggedAuth->fetchToken();
$apiInstance = new ObjectsApi( $twoLeggedAuth );
$bucket_key = $bucket_info['bucket_key'];
$filename = 'C:\wamp\www\nebnibim\storage\app\bibliothequeObjets\user69\13111006_IFCR2_Geo_Openings_1.ifc ';
$body = $filename;
$file = new SplFileObject( $body );
$content_length = $file->getSize();
$object_name = $file->getFilename();
//try {
$result2 = $apiInstance->uploadObject( $bucket_key, $object_name, $content_length, $body, null, null );
//step4
$urn = 'urn:adsk.objects:os.object:nebnibim51548575979/13111006_IFCR2_Geo_Openings_1.ifc';
$base64Urn = rtrim( strtr( base64_encode( $urn ), '+/', '-_' ), '=' );
$twoLeggedAuth->setScopes( [ 'data:read', 'data:write' ] );
$twoLeggedAuth->fetchToken();
$apiInstance2 = new DerivativesApi( $twoLeggedAuth );
$jobInput = array(
'urn' => 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bmVibmliaW01MTU0ODU3NTk3OS8xMzExMTAwNl9JRkNSMl9HZW9fT3BlbmluZ3NfMS5pZmM'
);
$jobPayloadInput = new JobPayloadInput( $jobInput );
$jobOutputItem = array(
'type' => 'svf',
'views' => array( '2d', '3d' )
);
$jobPayloadItem = new JobPayloadItem( $jobOutputItem );
$jobOutput = [
'formats' => array( $jobPayloadItem )
];
$jobPayloadOutput = new JobPayloadOutput( $jobOutput );
$job = new JobPayload();
$job->setInput( $jobPayloadInput );
$job->setOutput( $jobPayloadOutput );
$x_ads_force = false;
$resultat= $apiInstance2->translate( $job,$x_ads_force );
Looks like you are still uploading to a bucket named after system time, only to call job on a hard coded urn pointing an object that’s uploaded to another bucket earlier - this would always result in a 404 error as the urn is incorrect.
Follow the code sample and docs here to fetch a list of the contents of an existing bucket, verify the objects really exist at the time of query in your bucket, take the objectId returned that’s guaranteed to be current and correct, and go from there.
You will need to upload the files again after 24 hours as the bucket you created is transient. See here for more on this - and that should be the reason for the error we are seeing now.

Azure search - $skip in PHP

Let's say I have this code in PHP:
public function getFromAzure($searchParam, $jobCategory, $top, $skip, $request){
$listingManager = $this->get('rd.model_manager.job_listing');
$url = $listingManager->getAzureSearchParam($request, 'azure_search_idx');
$apiKey = $listingManager->getAzureSearchParam($request, 'azure_key');
$searchParam = preg_replace('/\s+/', '+', $searchParam);
$postdata = json_encode(
array(
'search' => $searchParam,
'filter' => $category,
'orderby'=> 'publishedDate desc',
'facets' => array('locationName','employmentType', 'workSchedule','jobFunction','positionLevel','industry'),
'top' => $top,
'skip' => $skip,
'count' => true
)
);
$opts = array(
'http'=>array(
'method'=>"POST",
'header'=>"Content-type: application/json\r\n" .
"api-key: ". $apiKey . "\r\n" .
"Accept: application/json",
'content'=>$postdata
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents($url, false, $context);
$file = json_decode($file,true);
return $file;
}
Is there a way I can iterate the $skip inside this function(PHP)?
Currently I am iterating skip through Ajax call from javascript. 1 ajax call per (15 record) skip.
I need to iterate the skip because I need to load about 2,000 records(and counting)on page load, which per query is limited to 1,000. and assuming if I have 10,000 records or more. then I would have to run ajax every 1000 (for example) which could have performance issue.
btw fyi only- I need this on facets. where I have to iterate throught all records and get their value of my facet categories.
Thank you in advance! Cheers!

How do you create an API that connects a form on a site to a CRM using PHP

I'm rather new to Gravity Forms and building API's using PHP. I need to create a script that whenever a Gravity Form is completed the API sends this as JSON data to a POST URL. They gave me the security key name and value, how do I do this using PHP? Do I need Jquery and/or AJAX?
EDIT:
This is what I have so far but I have no idea if I'm on the right path: (I omitted some fields with "X's" due to obvious potential security reasons)
<?php
function calculate_signature( $string, $private_key ) {
$hash = hash_hmac( 'sha1', $string, $private_key, true );
$sig = rawurlencode( base64_encode( $hash ) );
return $sig;
}
//set API keys
$api_key = 'XXXXXXX';
$private_key = 'XXXXXXXXXX';
//set route
$route = '/XXXXXXX.php';
//creating request URL
$expires = strtotime( '+60 mins' );
$string_to_sign = sprintf( '%s:%s:%s:%s', $api_key, 'POST', $route, $expires );
$sig = calculate_signature( $string_to_sign, $private_key );
$url = 'XXXXXXX.com' . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires;
// $form = array(
// array(
// 'title' => 'API Generated Form',
// 'description' => 'This is the description for the form generated by the API',
// 'labelPlacement' => 'top_label',
// 'button' => array(
// 'type' => 'text'
// ),
// 'confirmations' => array(
// array(
// 'id' => 0,
// 'name' => 'Default Confirmation',
// 'type' => 'message',
// 'message' => 'Thanks for contacting us! We will get in touch with you shortly.',
// 'isDefault' => true,
// ),
// ),
// 'fields' => array(
// array(
// 'id' => '1',
// 'label' => 'My Text',
// 'type' => 'text'
// )
// ),
// ),
// );
$form = array(
'age' => NULL
);
//json encode array
$form_json = json_encode( $form );
//retrieve data
$response = wp_remote_request( $url, array( 'method' => 'POST', 'body' => $form_json ) );
if ( wp_remote_retrieve_response_code( $response ) != 200 || ( empty( wp_remote_retrieve_body( $response ) ) ) ){
//http request failed
die( 'There was an error attempting to access the API.' );
}
//result is in the response "body" and is json encoded.
$body = json_decode( wp_remote_retrieve_body( $response ), true );
if( $body['status'] > 202 ){
$error = $body['response'];
//form insert failed, get error information
$error_code = $error['code'];
$error_message = $error['message'];
$error_data = isset( $error['data'] ) ? $error['data'] : '';
$status = "Code: {$error_code}. Message: {$error_message}. Data: {$error_data}.";
die( "Could not post forms. {$status}" );
}
$form_id = $body['response'][0];
echo 'The following form id was created: ' . $form_id . '</br>';
?>

Facebook Instant Articles PHP SDK debug line

I'm trying to transform my html page to Facebook Instant Articles format.
I keep getting on the screen
"DEBUG - =========================== DEBUG -"
When Im calling "$transformer->transformString" or "
$transformer->transform( $header, $document );"
Why that? I don't echo anything.
(This isn't wordpress site)
$header =
Header::create()
->withPublishTime(
Time::create( Time::PUBLISHED )->withDatetime(
\DateTime::createFromFormat(
'j-M-Y G:i:s',
date('j-M-Y G:i:s', strtotime($published_date))
))
)
->withModifyTime(
Time::create( Time::MODIFIED )->withDatetime(
\DateTime::createFromFormat(
'j-M-Y G:i:s',
date('j-M-Y G:i:s', strtotime($last_modified_date))
))
);
// Loads the rules configuration file
$rules_file_content = file_get_contents("rules-configuration.json", true);
// Load html content from a file.
//$content = file_get_contents("sample-html.html", true);
$content = get_the_content();
// Create a transformer object and load the rules
$transformer = new Transformer();
$transformer->loadRules($rules_file_content);
$document = new DOMDocument();
libxml_use_internal_errors(true);
$document->loadHTML( '<?xml encoding="' . $charset . '" ?><h1>' . $title . '</h1>' );
libxml_use_internal_errors(false);
$transformer->transform( $header, $document );
if($subtitle) {
$header->withSubTitle ($subtitle);
}
if ( $kicker ) {
$header->withKicker( $kicker );
}
define( 'IA_PLUGIN_VERSION', '4.0.5' );
$instant_article =
InstantArticle::create()
->withCanonicalUrl( $cannonical_link )
->withHeader( $header )
->addMetaProperty( 'op:generator:application', 'facebook-instant-articles' )
->addMetaProperty( 'op:generator:application:version', IA_PLUGIN_VERSION );
$instant_article->withStyle( 'default' );
$transformer->transformString( $instant_article, $content, $charset );
// Instantiate an API client
$client = Client::create(
$APP_ID,
$APP_SECRET,
$ACCESS_TOKEN,
$PAGE_ID,
$is_development
);
// Import the article
try {
$client->importArticle($instant_article, $is_published);
} catch (Exception $e) {
echo 'Could not import the article: '.$e->getMessage();
}
Add these lines :)
\Logger::configure(
[
'rootLogger' => [
'appenders' => ['facebook-instantarticles-traverser']
],
'appenders' => [
'facebook-instantarticles-traverser' => [
'class' => 'LoggerAppenderConsole',
'threshold' => 'INFO',
'layout' => [
'class' => 'LoggerLayoutSimple'
]
]
]
]);
Source: https://github.com/facebook/facebook-instant-articles-sdk-extensions-in-php/blob/master/examples/quiet_logger.php

Pushwoosh Phonegap notifications PHP method set tags

I am not a professional programmer. I manage with PHP and Javascript, but I am having a hard time converting Pushwoosh methods to functional PHP or Javascript. This is the method that I need help converting:
Method /setTags
Set tags values for device
Request:
{
"request":{
"application":"DEAD0-BEEF0",
"hwid": 'device hardware id',
"tags": {
"tag1": "string value",
"tag2": 42,
"tag3": "string",
"tag4": 3.14
}
}
}
This is how they post their methods. Any help with this?
I wrote a PHP to setTags but I could not verify it yet as I am still working on retrieving the Token. I have a question on that on this link:
Phonegap/Pushwoosh Android retrieving Device id / Token
this is my PHP for setTags. Does this look right using JSON? (I am running late on my project!)
<?php
define('PW_AUTH', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('PW_APPLICATION', 'xxxxxxxxxx');
define('HW_ID', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
function doPostRequest($url, $data, $optional_headers = null) {
$params = array(
'http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null)
$params['http']['header'] = $optional_headers;
$ctx = stream_context_create($params);
$fp = fopen($url, 'rb', false, $ctx);
if (!$fp)
throw new Exception("Problem with $url, $php_errmsg");
$response = #stream_get_contents($fp);
if ($response === false)
return false;
return $response;
}
function pwCall( $action, $data = array() ) {
$url = 'https://cp.pushwoosh.com/json/1.3/' . $action;
$json = json_encode( array( 'request' => $data ) );
$res = doPostRequest( $url, $json, 'Content-Type: application/json' );
print_r( #json_decode( $res, true ) );
}
pwCall( 'setTags', array(
'application' => PW_APPLICATION,
'auth' => PW_AUTH,
'hwid' => HW_ID,
'tags' => array(
array(
'tag1' => 'string value',
'tag2' => 42,
'tag3' => 'string',
'tag4' => 3.14
)
)
)
);
?>
you do not need to convert this JSON to send tags to Pushwoosh. It's being sent directly from the device to the Pushwoosh server.

Categories