IBM Watson 语音转文本"unable to transcode data stream audio/webm -> audio/x-float-array"媒体 MIME 类型



我正在使用mediaDevices.getUserMedia()在Chrome中录制短音频文件(几秒钟(,将文件保存到Firebase Storage,然后尝试将文件发送到IBM Watson Speech to Text。我收到这个错误消息:

unable to transcode data stream audio/webm -> audio/x-float-array

在浏览器中,我设置了麦克风:

navigator.mediaDevices.getUserMedia({ audio: true, video: false })
.then(stream => {
var options = {
audioBitsPerSecond : 128000,
mimeType : 'audio/webm'
};
const mediaRecorder = new MediaRecorder(stream, options);
mediaRecorder.start();
...

根据这个答案,Chrome只支持两种媒体类型

audio/webm
audio/webm;codecs=opus

我都试过了。

以下是我发给IBM Watson的内容:

curl -X POST -u "apikey:my-api-key" 
--header "Content-Type: audio/webm" 
--data-binary "https://firebasestorage.googleapis.com/v0/b/my-app.appspot.com/my-file" 
--url "https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/01010101/v1/recognize"

支持的MIME类型列表包括webmwebm;codecs=opus

我尝试录制并发送一个ogg格式的文件,但收到了相同的错误消息:

curl -X POST -u "apikey:my-api-key" 
--header "Content-Type: audio/ogg" 
--data-binary @/Users/TDK/LanguageTwo/public/1.ogg 
--url "https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/01010101/v1/recognize"

我尝试了IBM的示例音频文件,它运行得很好:

"transcript": "several tornadoes touched down as a line of severe thunderstorms swept through Colorado on Sunday "

我从谷歌云语音到文本收到了一条类似的错误消息。

创建一个名为watsonstt.sh的bash脚本(我建议保存在~/bin/中(,粘贴下面的内容,用自己的内容替换apikeyurlsavepath变量内容,并根据注释建议调用该脚本,包括单个参数的引号(用于处理空格(。

在撰写本文时,API凭证在IBM Watson云网络界面的"管理"选项卡中提供,您需要注册信用卡/借记卡详细信息。


#!/bin/bash
# call this script with one argument for posix file path parameter in quotes e.g.: 
# watsonstt.sh "/user/name/file.mp3"
# 500 mins per month for free
# https://www.ibm.com/watson/developercloud/speech-to-text/api/v1/curl.html?curl#get-token
apikey=XXXXXXXXXXXX
url=YYYYYYYYYY
savepath=~/Desktop/${1##*/}.txt
curl -X POST -u "apikey:$apikey" --header "Content-Type: audio/${1##*.}" --data-binary @"$1" "$url/v1/recognize?timestamps=true&max_alternatives=3" -o "${savepath}"

最新更新