'How to tell googlespeech recognition to use a specific phraseset 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
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
