Voice recognition failed miserably: Wrong status code 401 in Bing Speech API / token - node.js

When I was trying to translate a sample audio from English to some other language using Azure Bing Speech to Text Api, I am getting Error: Voice recognition failed miserably: Wrong status code 401 in Bing Speech API / token
I have tried increasing open_timeout to a higher value like 50000(which was suggested for slow-internet) hard-coded in bingspeech-api-client in Line 110 , but still the error persists.
let audioStream = fs.createReadStream('hello.wav');
// Bing Speech Key (https://www.microsoft.com/cognitive-services/en-us/subscriptions)
let subscriptionKey = '******';
let client = new BingSpeechClient(subscriptionKey);
client.recognizeStream(audioStream).then(function(response)
{
console.log("response is ",response);
console.log("-------------------------------------------------");
console.log("response is ",response.results[0]);
}).catch(function(error)
{
console.log("error occured is ",error);
});
This code should generate the text from that sample audio file.

Code 401 means unauthorized - wrong key in your case. I suspect you followed an outdated version of some tutorial since by now the service is not called Bing Speech API anymore. See here for a current tutorial using the microsoft-cognitiveservices-speech-sdk SDK for node.js.
https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/quickstart-js-node#use-the-speech-sdk

Related

Unable to extract log from watson assistant

Please I have struggling with consuming watson assistant log API. currently we use watson assistant log API for fetching daily conversation log between our chatbot and customer and feed the log into NLC for classifying the intents for precision analyst. Recently we observed that IBM has decomission the NLC and advice that we migrate to NLU. since then we've being having issues getting the component running.
right now the assistant log return empty log for this filter 
authenticator = IAMAuthenticator('********')
assistant = AssistantV2(
version='2021-06-14',
authenticator = authenticator
)
assistant.set_service_url('https://api.eu-gb.assistant.watson.cloud.ibm.com')
print("The assistant URL ")
response=assistant.list_logs(
assistant_id='******', page_limit=100, filter='response_timestamp>2022-09-14T00:00:00.000Z',
cursor=cursor).get_result()
response=assistant.list_logs(
assistant_id='*******').get_result()
print(json.dumps(response, indent=2))
#print("the response is ",response)
this is returning an empty data
{
"logs": [],
"pagination": {}
}
Here are some reasons why this may occur.
You are using V2 API which requires an Enterprise account. If you only have Plus then you can use the V1 API. But there is no guarantee it will continue to work as expected in the future.
You don't have any logs for that date range. Check in the Analytics page.
An issue in your code. Try running the sample code on the REST API docs. If this works then compare against your code.
Your filter looks ok, but try this filter (change language and assistant ID):
language::en,request.context.system.assistant_id::<YOUR_ASSISTANT_ID>,response_timestamp>2022-09-14T00:00:00.000Z
Seeing as you have midnight as your time, you can also change that part to:
response_timestamp>2022-09-14

Fullfillment error "Platform "GOOGLE_HANGOUTS' not supported." when using inline editor to fulfill my code after hitting an API

I am hitting an API and returning required values to a chat-bot. Though I am getting response in Dialogflow's Default Response Simulator but for the same code I am not getting any response in Hangout chat API (I have integrated Dialogflow with Hangout chat).
function func_name(agent){
const abcd = agent.parameters.abcd;
agent.add(`Below are the products related to ${abcd}`);
return axios.get(`https://*********************/****/${abcd}`)
.then((result)=>{
result.data.map(abcdObj => {
agent.add(JSON.stringify(abcdObj.name+"~"+abcdObj.key));
});
});
and the error message what I am receiving is:
Error: Platform 'GOOGLE_HANGOUTS' not supported.
Function execution took 12 ms, finished with status: 'crash'
So, here I got solution for the issue by google. You will have to upgrade the version of dependencies , dialogflow version to 0.7.0 and dialogflow-fulfillment to 0.6.1 in package.json of your fulfillment code and if your bot still doesn't work try to create new bot with same functionality. It will help for sure.

400 Bad Request & Update for Getting Token for Microsoft Translator API Azure

I have an old system that has been using the Microsoft Translator API before we were asked to get a subscription with Azure.
One thing that was being translated was the date on a certificate that was being generated from a LibreOffice template using a function in groovy and jooscript in the template itself.
The date was being translated from English to Chinese and was constructed using SimpleDateFormat("dd MMMM yyyy").
Since the change/update, we have been getting this error:
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: http://api.microsofttranslator.com/v2/Http.svc/Translate?text=06+December+2017&from=en&to=zh-CHT
The request being sent to the API: Translate?text=06+December+2017&from=en&to=zh-CHT
Found that when we change the text to anything it gives the same response, i.e. translating "Hello" would give the same error.
Expected response: 六 日 十二 月 二零一七年,i.e. 6 day, 12 month,2017 year. although the format is changed using SimpleDateFormat to dd MMM yyyy.
This is the groovy function being called in the LibreOffice template using jooscript field script:
public String translate(String text, String from, String to){
def client = new
RESTClient("http://api.microsofttranslator.com/v2/Http.svc/Translate")
client.get(path:'', query:[text:"$text", from:"$from", to:"$to"], headers:
["Authorization":"Bearer ${getToken()}"]).xml
}
Does anyone know why this error is now occurring?
I want to know how do I update the below code (if it needs to be updated) to work with the new Microsoft Translator API Azure store so I can include the Ocp-Apim-Subscription-Key, https://api.cognitive.microsoft.com/sts/v1.0/issueToken and such. Do I still need the ID and secret?
Please note that I didn't write the original code, and the company seems to have lost access to the old account that provided the credentials for the translation and such.
def id = *********
def secret = *********
def getToken = {
def client = new
RESTClient("https://datamarket.accesscontrol.windows.net/v2/OAuth2-13")
try{
client.post(){
type "application/x-www-form-urlencoded"
urlenc client_id:id , client_secret:secret , scope: "http://api.microsofttranslator.com", grant_type: "client_credentials"
}.json.access_token
}
catch(e){
e.printStackTrace(); return null;
}
Microsoft DataMarket retired April 2017so the client-secret and client-Id will no longer work. The Microsoft Translator API has moved to the Microsoft Azure portal. You will need to:
create an Azure account and
subscribe to Azure and subsequently
subscribe to the Translator API and
make minor code changes to the oAuth token.
You can find detailed instructions on the above steps at: https://cognitive.uservoice.com/knowledgebase/articles/1128340-microsoft-translator-moves-to-the-azure-portal
Please let us know if you have any further questions.
Kindly,
Gwenda
Microsoft Translator Team

How do I manually refresh-token while creating apps using Zapier CLI

I want to perform refresh token but my gateway gives HTTP response 403 instead of 401 so I cannot use 'autoRefresh' feature of Zapier.
I tried throwing 'RefreshTokenException' when the response status is 403 as given below:
return responsePromise
.then((response) => {
if (response.status == 403) {
throw new RefreshTokenException();
}
...
});
But upon doing this I get an Error from Zapier (while creating zaps) stating:
RefreshTokenException is not defined
Can anyone help me with manually refreshing token using Zapier CLI platform for app creation?
David here, from the Zapier Platform team. Sorry for the slow reply, we're just now seeing some of these.
It's not defined because that's not an error we define. You've got the right idea, you just need to use RefreshAuthError instead. See these docs.
​Let me know if you've got any other questions!

How can a bot receive a voice file from Facebook Messenger (MP4) and convert it to a format that is recognized by speech engines like Bing or Google?

I'm trying to make a bot for Facebook Messenger using Microsoft's Bot Framework that will do this:
Get a user's voice message sent via Facebook Messenger
Convert speech to text
Do something with it
There's no problem with getting the voice message from Messenger (the URL can be extracted from the message the bot receives), and there's also no problem with converting an audio file to speech (using Bing Speech API or Google's similar API).
However, these APIs require PCM (WAV) files, while Facebook Messenger gives you an MP4 file.
Is there a popular/standard way of converting one format into another that is used in writing the bots?
So far my best idea is to run vlc.exe as a console job on my server and convert the file, but that doesn't sound like the best solution.
Developed a solution that works as follows:
Receive voice message from facebook
Download the MP4 file to local disk using the link inside Activity.Attachments
Use MediaToolKit (wrapper for FFMPEG) to convert MP4/AAC to WAV on local server
Send the WAV to Bing Speech API
So the answer to my question is: use MediaToolKit+ffmpeg to convert the file format.
Sample implementation and code here: https://github.com/J3QQ4/Facebook-Messenger-Voice-Message-Converter
public string ConvertMP4ToWAV()
{
var inputFile = new MediaFile { Filename = SourceFileNameAndPath };
var outputFile = new MediaFile { Filename = ConvertedFileNameAndPath };
using (var engine = new Engine(GetFFMPEGBinaryPath()))
{
engine.Convert(inputFile, outputFile);
}
return ConvertedFileNameAndPath;
}

Resources