【问题标题】:How to request multiple channels using IBM Cloud Speech to Text API如何使用 IBM Cloud Speech to Text API 请求多个频道
【发布时间】:2020-04-30 21:04:36
【问题描述】:

我想在 IBM Cloud 上使用语音转文本将 wav 文件转换为文本。 如何发送请求以获取两个渠道的结果? 我使用 websocketAPI 吗? 如果有,参数中是否有通道规范?

谁能告诉我?

【问题讨论】:

  • 你应该先尝试一下,然后再直接询问答案。

标签: api request channel speech


【解决方案1】:

感谢您的回复。

我正在尝试使用 javascript 进行 websocket 连接。 在下面的程序中,没有“websocket.send (blob);”的响应。 blob对应的信息不正确吗?

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<script>
var websocket = null;
function start() {
    var IAM_access_token = "{my-token}";
    var wsURI = 'wss://gateway-tok.watsonplatform.net/speech-to-text/api/v1/recognize'
      + '?access_token=' + IAM_access_token
      + '&model=ja-JP_BroadbandModel';
    console.log(wsURI);
    websocket = new WebSocket(wsURI);
    websocket.onopen = function(evt) { onOpen(evt) };
    websocket.onclose = function(evt) { onClose(evt) };
    websocket.onmessage = function(evt) { onMessage(evt) };
    websocket.onerror = function(evt) { onError(evt) };

}

function onOpen(evt) {
  var message = {
    'action': 'start',
    'content-type': 'audio/wav'
  };
  console.log(JSON.stringify(message));
  websocket.send(JSON.stringify(message));
}

function onClose(evt) {
  websocket.close();
}

function onMessage(evt) {
  console.log(evt);
}

function onError(evt) {
  console.log(evt);
}

function sendfile() {
    console.log("send click!");
    console.log(document.getElementById( "data" ));
    var blob = document.getElementById( "data" );
    websocket.send(blob) ;
}
</script>
</head>
<body>
<form method="post" enctype="multipart/form-data">
  <div id="wrap">
    <button type="button" onclick="start();">start</button>
    <input type="file" id="data" name="data">
        <button type="button" id="send" onclick="sendfile();">send</button>
  </div>
</form>
</body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-28
    • 2018-11-18
    • 1970-01-01
    • 2012-10-04
    • 2020-05-26
    • 2019-04-02
    • 2022-09-26
    相关资源
    最近更新 更多