【问题标题】:Speech to text bing speech API Azure语音转文本 bing 语音 API Azure
【发布时间】:2017-03-03 04:36:24
【问题描述】:

当我尝试执行下面的代码时,我收到以下错误:

(node:3784) UnhandledPromiseRejectionWarning: UnhandledPromiseRejectionWarning: Unhandled Promise Rejection (rejection id: 1): Error: 语音识别惨遭失败: socket hang up

var fs = require('fs');
var bing = require('bingspeech-api-client');

var audioStream = fs.createReadStream('d:\\node.wav'); 
var subscriptionKey = 'xxxxxxxxxxxxxxxxx';

var client = new bing.BingSpeechClient(subscriptionKey);
client.recognizeStream(audioStream)
      .then(response => console.log(response.results[0].name));

请帮帮我。

【问题讨论】:

  • 嗨 Adhit,你有任何更新吗?
  • 我用 ibm watson 完成了这个模块。今天我要调查这些事情,我会让你尽快知道。
  • 还是一样的错误加里

标签: node.js speech-to-text bing-speech


【解决方案1】:

我尝试使用您的代码 sn-p 和位于 https://github.com/palmerabollo/bingspeech-api-client/tree/master/examples 的存储库中的示例音频文件。它在我这边工作得很好。

深入源码,发现报错信息是由
throw new Error(`Voice recognition failed miserably: ${err.message}`);
https://github.com/palmerabollo/bingspeech-api-client/blob/master/src/client.ts#L129

一般是网络问题,请仔细检查你的网络,或者你可以尝试 ping url https://api.cognitive.microsoft.com/sts/v1.0/issueToken 来检查你是否有连接到 API 的问题。

【讨论】:

    【解决方案2】:

    在使用服务时遇到问题,这是由于第 110 行的 bingspeech-api-client 中硬编码的超时设置:

    open_timeout: 5000,
    

    Full code 在这里。

    您可能想尝试根据您的互联网连接设置更高的值。

    【讨论】:

    • 我尝试了 10000 到 50000 的多个值,仍然无法正常工作,wav 文件的比特率重要吗?
    【解决方案3】:

    如果您使用代理服务器,请尝试使用

    node_modules\bingspeech-api-client\lib\client.js 文件中设置代理

    https-proxy-agent

    在所有 http 请求的选项中,包括问题令牌。

    【讨论】:

      【解决方案4】:

      下面的代码对我有用

      const { BingSpeechClient, VoiceRecognitionResponse } = require('bingspeech-api-client');
      const fs = require('fs');
      let audioStream = fs.createReadStream("audiowav.wav"); 
      
      // Bing Speech Key (https://www.microsoft.com/cognitive-services/en-us/subscriptions)
      let subscriptionKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';         
      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);
                });
      

      我认为您需要从 bingspeech-api-client 导入 BingSpeechClient、VoiceRecognitionResponse。 这里是参考bingspeech-api-client

      【讨论】:

        猜你喜欢
        • 2017-10-29
        • 1970-01-01
        • 2012-09-29
        • 2019-01-06
        • 2018-03-29
        • 1970-01-01
        • 2021-09-06
        • 2023-03-03
        • 2022-11-14
        相关资源
        最近更新 更多