How to tell googlespeech recognition to use a specific phraseset node.js - node.js

We have an evolving Node.js app where we had experimented with:
config: {
encoding: "MULAW",
sampleRateHertz: 8000,
languageCode: "en-US",
useEnhanced: true,
model: 'phone_call',
"speechContexts": [{
"phrases": [
{ "value": "battalion", "boost": 10 },
{ "value": "italian", "boost": -10 },
]
}
]
},
singleUtterance: false,
interimResults: true
};
And after some iterative prototypes we also learned how to load phraseset into the google cloud .. so for example our phraseset that can be set and inspected is similar to:
.createPhraseSet({
phraseSet: {
name: "second",
phrases: newPhrases
},
phraseSetId: "PUSDA01",
parent: "projects/project-id/locations/global",
})
.then((res) => {
console.log("speech api res +++", res);
console.log("speech api res 218 +++", JSON.stringify(res));
});
So instead of "speechContexts" being an array pushed on every recognition request we want to our config to tell google to use phraset id "PUSDA01" ... please advise on syntax.
I do not readily see how in: https://googleapis.dev/java/google-api-grpc/0.62.0/com/google/cloud/speech/v1p1beta1/SpeechContext.html

Assuming that the phraseset is already created and you know its name, phraseset could be defined in the config. See code below on how to define it in the config. See RecognitionConfig for the reference.
NOTE: Though I don't have the actual audio to test, but this syntax should work. Use the updated config for recognition. I used your created phraseset with phraseid PUSDA01 as the example:
const phraseSets = {
phraseSets: [
{
name: "projects/your-project-number/locations/global/phraseSets/PUSDA01"
}
]
};
config: {
encoding: "MULAW",
sampleRateHertz: 8000,
languageCode: "en-US",
useEnhanced: true,
model: 'phone_call',
adaptation: phraseSets
},
singleUtterance: false,
interimResults: true
};
If ever you have multiple phraseSets or don't know the name of your phraseSets, you can use listPhraseSet() to get all your available phrases.

Related

Usage of Bing SpellChecker into LUIS.ai

I try to improve LUIS intents prediction accuracy. Because there is an issue when missing one letter leads LUIS to a wrong intent.
I use the tutorial, but still there is no promised key like alteredQuery in the JSON returned form LUIS.
EXPECTATION:
"query": "bouk me a fliht to kayro",
"prediction": {
"alteredQuery": "book me a flight to cairo",
"topIntent": "book a flight",
"intents": {
"book a flight": {
"score": 0.9480589
}
"None": {
"score": 0.0332136229
}
},
"entities": {}
}
}
REALITY:
"query": "bouk me a fliht to kayro",
"prediction": {
"topIntent": "book a flight",
"intents": {
"book a flight": {
"score": 0.9480589
}
"None": {
"score": 0.0332136229
}
},
"entities": {}
}
}
This is how I use it:
const luisConfig: LuisApplication = {
applicationId: [APP_ID_GOES_HERE],
endpointKey: [KEY_GOES_HERE],
endpoint: [ENDPOINT_GOES_HERE],
};
const recognizerOptions: LuisRecognizerOptionsV2 = {
apiVersion: 'v2',
bingSpellCheckSubscriptionKey: [KEY_GOES_HERE];
includeAllIntents: true,
log: true,
spellCheck: true,
log: true,
includeInstanceData: true
};
const luisRecognizer = new LuisRecognizer(luisConfig, recognizerOptions, true);
I have the same issue... if I call the API directly:
/luis/prediction/v3.0/apps/<xxxxx>/slots/production/predict?verbose=true&show-all-intents=false&log=true&subscription-key=<xxxxx>&mkt-bing-spell-check-key=<xxxxx>&query=gretings
The response have not the object "alteredQuery".
Im also try with more parameters with the same result:
https://<xxxxx>.cognitiveservices.azure.com/luis/prediction/v3.0/apps/<xxxxx>/slots/production/predict?verbose=true&show-all-intents=false&log=true&subscription-key=<xxxxx>&spellCheck=true&mkt-bing-spell-check-key=<xxxxx>&bing-spell-check-subscription-key=<xxxxx>&query=gretings
If I call directly the BING API with the Ocp-Apim-Subscription-Key header, they response correctly:
https://api.bing.microsoft.com/v7.0/spellcheck?text=gretings

Creating AWS S3 object life cycle using NodeJS

Creating AWS S3 object life cycle using NodeJS.
I want to create S3 object life cycle via API using NodeJS. When I see the documentation, AWS provided only multiple object life cycle, with Java.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-set-lifecycle-configuration-intro.html
I also checked this url -
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getBucketLifecycle-property
Genral Concern
How to set multiple Transition with NodeJS like the way Java has ?
BucketLifecycleConfiguration.Rule rule2 = new BucketLifecycleConfiguration.Rule()
.withId("Archive and then delete rule")
.withFilter(new LifecycleFilter(new LifecycleTagPredicate(new Tag("archive", "true"))))
.addTransition(new Transition().withDays(30).withStorageClass(StorageClass.StandardInfrequentAccess))
.addTransition(new Transition().withDays(365).withStorageClass(StorageClass.Glacier))
.withExpirationInDays(3650)
.withStatus(BucketLifecycleConfiguration.ENABLED);
Followed by -
https://docs.aws.amazon.com/AmazonS3/latest/userguide/how-to-set-lifecycle-configuration-intro.html
Any help would be great.
we need to call putBucketLifecycle and pass Rules Array to LifecycleConfiguration. Similar to CLI Example
s3.putBucketLifecycle(
{
Bucket: "sample-temp-bucket",
LifecycleConfiguration: {
Rules: [
{
Filter: {
And: {
Prefix: "myprefix",
Tags: [
{
Value: "mytagvalue1",
Key: "mytagkey1",
},
{
Value: "mytagvalue2",
Key: "mytagkey2",
},
],
},
},
Status: "Enabled",
Expiration: {
Days: 1,
},
},
{
Filter: {
Prefix: "documents/",
},
Status: "Enabled",
Transitions: [
{
Days: 365,
StorageClass: "GLACIER",
},
],
Expiration: {
Days: 3650,
},
ID: "ExampleRule",
},
],
},
},
(error, result) => {
if (error) console.log("error", error);
if (result) console.log("result", result);
}
);

TagSpecifications with requestSpotInstances UnexpectedParameter with aws-sdk

I'm trying to add a tag to my AWS Spot Request. But it has returned me { UnexpectedParameter: Unexpected key 'TagSpecifications' found in params.LaunchSpecification.
I have followed this documentation, and I have already tried to move this code out of LaunchSpecification, but the error persists.
const params = {
InstanceCount: 1,
LaunchSpecification: {
ImageId: config.aws.instanceAMI,
KeyName: 'backoffice',
InstanceType: config.aws.instanceType,
SecurityGroupIds: [config.aws.instanceSecurityGroupId],
TagSpecifications: [{
ResourceType: 'instance',
Tags: [{
Key: 'Type',
Value: 'Mongo-Dump',
}],
}],
BlockDeviceMappings: [{
DeviceName: '/dev/xvda',
Ebs: {
DeleteOnTermination: true,
SnapshotId: 'snap-06e838ce2a80337a4',
VolumeSize: 50,
VolumeType: 'gp2',
Encrypted: false,
},
}],
IamInstanceProfile: {
Name: config.aws.instanceProfileIAMName,
},
Placement: {
AvailabilityZone: `${config.aws.region}a`,
},
},
SpotPrice: config.aws.instancePrice,
Type: 'one-time',
};
return ec2.requestSpotInstances(params).promise();
Something makes me think that the problem is in the documentation or in the aws-sdk for Javascript itself. My options are exhausted.
The error message is correct. According to the documentation, the RequestSpotLaunchSpecification object doesn't have an attribute called TagSpecifications.
However, you can tag your Spot Instance request after you create it.
ec2.requestSpotInstances(params) returns an array of SpotInstanceRequest objects, each containing a spotInstanceRequestId (e.g. sir-012345678). Use the CreateTags API with these Spot Instance request ids to add the tags.
const createTagParams = {
Resources: [ 'sir-12345678' ],
Tags: [
{
Key: 'Type',
Value: 'Mongo-Dump'
}
]
};
ec2.createTags(createTagParams, function(err, data) {
// ...
});

Dialogflow API V2 largeImage for MediaObject not working

I recently switched from the V1 to V2 for dialogflow and I'm updating my webhook.
I use mediaObjects with large Images in my agent as a personal taste.
Unfortunately I can't seem to make it work for the V2.
My current code for the media object is this:
conv.ask(new MediaObject({
name: 'Name',
largeImage: new Image({
url: 'https://[...].jpg',
alt: 'alternative'
}),
url: 'https://[...].mp3',
description: 'description'
}));
As you can see, I used the largeImage field, as I found it in the JSON section of Google's example . As the documentation is inexistant, I'm checking the node.js library for information and I verified that the largeImage field extends the Image interface so it should be correct.
It works when I switch largeImage for Icon but I don't like it.
My JSON response is like this:
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "text"
}
},
{
"mediaResponse": {
"mediaType": "AUDIO",
"mediaObjects": [
{
"contentUrl": "https://[...].mp3",
"description": "description",
"name": "name"
}
]
}
}
],
"suggestions": [
{
"title": "Not yet implemented"
}
]
},
"userStorage": "{\"data\":{}}"
}
}
For some reason the largeImage field doesn't appear in my JSON but there isn't any error appearing anywhere.
Some of the APIs in JSON do not match the Node.js parameters. For example, largeImage in JSON is actually image in the MediaObjectOptions definition.

Creating azure VM from image with Node SDK

I'm trying to use the azure sdk (azure-sdk-for-node) to create a virtual machine based on an image i've already saved. I've also already created the service.
Here is what I've got:
// Create a virtual machine in the cloud service.
computeManagementClient.virtualMachines.createDeployment('prerender-pro', {
name: "prerender-pro",
deploymentSlot: "Production",
label: "for heavy duty caching",
roles: [{
roleName: "prerender-pro",
roleType: "PersistentVMRole",
label: "for heavy duty caching",
oSVirtualHardDisk: {
sourceImageName: "prerender-os-2014-07-16",
mediaLink: "https://XXXXXXX.blob.core.windows.net/vhds/prerender-os-2014-07-16.vhd"
},
dataVirtualHardDisks: [],
configurationSets: [{
configurationSetType: "LinuxProvisioningConfiguration",
adminUserName: "Blah",
adminPassword: "Blahblah2014!",
computerName: 'prerender-pro',
enableAutomaticUpdates: true,
resetPasswordOnFirstLogon: false,
storedCertificateSettings: [],
inputEndpoints: []
}, {
configurationSetType: "NetworkConfiguration",
subnetNames: [],
storedCertificateSettings: [],
inputEndpoints: [{
localPort: 3389,
protocol: "tcp",
name: "RemoteDesktop"
}]
}]
}]
}, function (err, result) {
if (err) {
console.error(err);
} else {
console.info(result);
}
});
And the error I'm getting is this. I follow the example in the github readme almost exactly. Not sure why this is an issue.
{ [Error: A computer name must be specified.]
code: 'BadRequest',
statusCode: 400,
requestId: '9206ea1e591eb4dd8ea21a9196da5d74' }
Thanks!
It turns out that the error message is inaccurate. When deploying a Linux instance, only the "HostName" is required when defining the Configuration Set. "ComputerName" applies only to Windows instances. Here's an example of C# code:
ConfigurationSet configSet = new ConfigurationSet
{
HostName = "VMTest",
UserName="xxxxx",
UserPassword="xxxx",
ConfigurationSetType = ConfigurationSetTypes.LinuxProvisioningConfiguration
}

Resources