0
votes

I have developed Microsoft bot framework node js bot and connected to Facebook. When I am trying to add speech service to bot using facebook mic, am getting below error.

I have gone through the link sample code but getting below error when I am giving voice input through FB mic.

Error: ENOENT: no such file or directory, open 'D:\home\site\wwwroot\https:\cdn.fbsbx.com\'

below is the code snippet, function "fs.createReadStream()" generating error:

 async function openPushStream(filename) {
        // create the push stream we need for the speech sdk.
        console.log('---from  open push stream funcion ----',filename);
        var pushStream = sdk.AudioInputStream.createPushStream();

        // open the file and push it to the push stream.
        request(filename).pipe(fs.createWriteStream('userInputVoice.wav'))

        fs.createReadStream(filename).on('data', function(arrayBuffer) {
            pushStream.write(arrayBuffer.buffer);
        }).on('end', function() {
            pushStream.close();
        });

    var audioConfig = sdk.AudioConfig.fromStreamInput(pushStream);
    var speechConfig = sdk.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion);
    // Setting the recognition language to English.
speechConfig.speechRecognitionLanguage = "en-US";
// Create the speech recognizer.
var recognizer = new sdk.SpeechRecognizer(speechConfig, audioConfig);
recognizer.recognizeOnceAsync(
  function (result) {
    console.log(result);

    recognizer.close();
    recognizer = undefined;
    return result;
  },
  function (err) {
    console.trace("err - " + err);

    recognizer.close();
    recognizer = undefined;
  });
        return null;
    }

Please suggest, how to handle this issue. Thanks in advance.

I look forward for your response/suggestions.

1
Some code would be helpfull. Or an errorlog referring to the part of the code that fails. - Hessel
@Hessel, I have kept the code snippet in my question . Please look into it and let me know you suggestion to resolve this issue. - Anil
"D:\home\site\wwwroot\https:\cdn.fbsbx.com\" does not make any sense. Any idea why filename resolved into that? - Hessel
@Hessel, when I give the voice input through FB mic, we are receiving the input URL in " context._activity.channelData.message.attachments[0].payload.url" but when fs.createReadStream(filename) function appends "D:\home\site\wwwroot\" path to my input voice URL which leads to error "no such file or directory". - Anil
Tnx. Does not make any sense sorry. I would suggest to file a bug in the sample repo and fot the time being remove the prefix yourself in your code and see if that helps. - Hessel

1 Answers

1
votes

You can control the path value that is read from the created stream by passing the fd property in as an option when you call fs.createReadStream (you can read more about it here). Setting it to 0 tells the system not to pre-pend the stream path with the local pathway. Be aware that the open event will not be called when fd is passed in.

When tested, this unblocked my code. I was receiving the same error due to a similar pre-pended path as you (e.g. "c:\...\...\https:\someSite.com\someFile").

let readStream = fs.createReadStream(inputStream, {
  fd: 0
});

Adjusting your code to this should work for you.

request(filename).pipe(fs.createWriteStream('userInputVoice.wav', {
  fd: 0
}))

Hope of help!