大于 ~7mb 的文件在 IBM Watson Speech-To-Text 异步 createJob 调用中抛出 "Response not received."
Files larger than ~7mb throws "Response not received." on IBM Watson Speech-To-Text async createJob call
我正在处理服务器端语音到文本的转录,我能够得到一个 post 端点来处理较小的文件,但是任何大于 ~7Mb 的文件都会抛出一个错误对我来说很有意义。
我知道此代码适用于小文件,并且回调 URL 已正确注册。我试过在 setTimeout() 函数中创建 "readableTranscriptStream",只是为了确保这不是完整文件未传递给 createJob 调用的问题。我也试过只传递 req.file.buffer 作为音频参数的参数。我也知道这不是文件编码不正确的问题,因为我使用了相同的音频文件,慢慢增加文件的长度和大小直到它抛出这个错误,并且它一直有效直到我点击7.2Mb,或 .wav 16 位编码文件中约 3 分钟的音频。
我也尝试过使用 fs.createFileStream('./local_test.wav') 作为参数并返回相同的错误,尽管当我尝试时,_requestBodyLength 字段在错误是 10485760,_requestBodyBuffers 是一个对象数组。我意识到这个 10485760 与 maxBodyLength 相同,但是 API 的文档说 "You can pass a maximum of 1 GB and a minimum of 100 bytes of audio with a request",测试音频也是 ~7.2 Mb。
username: process.env.wastonUsername,
password: process.env.watsonPassword,
url: 'https://stream.watsonplatform.net/speech-to-text/api/'
});
const storage = multer.memoryStorage();
const upload = multer({ storage: storage , limit: {fields: 1, fileSize: 209715200, files:1, parts:2}});
upload.single('track')(req,res, (err) => {
req.setTimeout(0);
if (err) {
console.log(err);
return res.status(400).json({ message: err })
}
const registerCallbackParams = {
callback_url: <my_callback_url>,
user_secret: "Test"
};
const readableTranscriptStream = new Readable();
readableTranscriptStream.push(req.file.buffer);
readableTranscriptStream.push(null);
const createJobParams = {
audio: readableTranscriptStream,
callback_url: <my_callback_url>,
content_type: req.file.mimetype,
events:"recognitions.completed_with_results",
inactivity_timeout: -1
};
speechToText.createJob(createJobParams)
.then(recognitionJob => {
console.log(recognitionJob);
})
.catch(err => {
console.log('error:', err);
});
})
我返回的错误是:
error:{
Error: Response not received. Body of error is HTTP ClientRequest object
at formatError (/app/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:111:17 )
at /app/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:259:19 at process._tickCallback (internal/process/next_tick.js:68:7 )
message:'Response not received. Body of error is HTTP ClientRequest object',
body:Writable {
_writableState:WritableState {
objectMode:false,
highWaterMark:16384,
finalCalled:false,
needDrain:false,
ending:false,
ended:false,
finished:false,
destroyed:false,
decodeStrings:true,
defaultEncoding:'utf8',
length:0,
writing:false,
corked:0,
sync:true,
bufferProcessing:false,
onwrite:[
Function:bound onwrite
],
writecb:null,
writelen:0,
bufferedRequest:null,
lastBufferedRequest:null,
pendingcb:0,
prefinished:false,
errorEmitted:false,
emitClose:true,
bufferedRequestCount:0,
corkedRequestsFree:[
Object
]
},
writable:true,
_events:[
Object:null prototype
] {
response:[
Function:handleResponse
],
error:[
Function:handleRequestError
]
},
_eventsCount:2,
_maxListeners:undefined,
_options:{
maxRedirects:21,
maxBodyLength:10485760,
protocol:'https:',
path:'/speech-to-text/api/v1/recognitions?callback_url=<my_callback_url>&events=recognitions.completed_with_results&inactivity_timeout=-1',
method:'post',
headers:[
Object
],
agent:[
Agent
],
auth:undefined,
hostname:'stream.watsonplatform.net',
port:null,
nativeProtocols:[
Object
],
pathname:'/speech-to-text/api/v1/recognitions',
search:'?callback_url=<my_callback_url>&events=recognitions.completed_with_results&inactivity_timeout=-1'
},
_ended:false,
_ending:true,
_redirectCount:0,
_redirects:[
],
_requestBodyLength:0,
_requestBodyBuffers:[
],
_onNativeResponse:[
Function
],
_currentRequest:ClientRequest {
_events:[
Object
],
_eventsCount:6,
_maxListeners:undefined,
output:[
],
outputEncodings:[
],
outputCallbacks:[
],
outputSize:0,
writable:true,
_last:true,
chunkedEncoding:false,
shouldKeepAlive:false,
useChunkedEncodingByDefault:true,
sendDate:false,
_removedConnection:false,
_removedContLen:false,
_removedTE:false,
_contentLength:null,
_hasBody:true,
_trailer:'',
finished:false,
_headerSent:false,
socket:null,
connection:null,
_header:null,
_onPendingData:[
Function:noopPendingOutput
],
agent:[
Agent
],
socketPath:undefined,
timeout:undefined,
method:'POST',
path:'/speech-to-text/api/v1/recognitions?callback_url=<my_callback_url>&events=recognitions.completed_with_results&inactivity_timeout=-1',
_ended:false,
res:null,
aborted:1558070725953,
timeoutCb:null,
upgradeOrConnect:false,
parser:null,
maxHeadersCount:null,
_redirectable:[
Circular
],
[
Symbol(isCorked)
]:false,
[
Symbol(outHeadersKey)
]:[
Object
]
},
_currentUrl:'https://stream.watsonplatform.net/speech-to-text/api/v1/recognitions?callback_url=<my_callback_url>&events=recognitions.completed_with_results&inactivity_timeout=-1'
}
}
限制为 1GB,请确保您在提交时使用的是 Chunked 传输编码,这是输送大文件时常见的错误原因。 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding
尝试在实例化 SpeechToText 时添加 maxContentLength: Infinity
作为选项
const speechToText = new SpeechToTextV1({
username: 'user',
password: 'pass',
version: '2019-01-01',
maxContentLength: Infinity,
});
我正在处理服务器端语音到文本的转录,我能够得到一个 post 端点来处理较小的文件,但是任何大于 ~7Mb 的文件都会抛出一个错误对我来说很有意义。
我知道此代码适用于小文件,并且回调 URL 已正确注册。我试过在 setTimeout() 函数中创建 "readableTranscriptStream",只是为了确保这不是完整文件未传递给 createJob 调用的问题。我也试过只传递 req.file.buffer 作为音频参数的参数。我也知道这不是文件编码不正确的问题,因为我使用了相同的音频文件,慢慢增加文件的长度和大小直到它抛出这个错误,并且它一直有效直到我点击7.2Mb,或 .wav 16 位编码文件中约 3 分钟的音频。
我也尝试过使用 fs.createFileStream('./local_test.wav') 作为参数并返回相同的错误,尽管当我尝试时,_requestBodyLength 字段在错误是 10485760,_requestBodyBuffers 是一个对象数组。我意识到这个 10485760 与 maxBodyLength 相同,但是 API 的文档说 "You can pass a maximum of 1 GB and a minimum of 100 bytes of audio with a request",测试音频也是 ~7.2 Mb。
username: process.env.wastonUsername,
password: process.env.watsonPassword,
url: 'https://stream.watsonplatform.net/speech-to-text/api/'
});
const storage = multer.memoryStorage();
const upload = multer({ storage: storage , limit: {fields: 1, fileSize: 209715200, files:1, parts:2}});
upload.single('track')(req,res, (err) => {
req.setTimeout(0);
if (err) {
console.log(err);
return res.status(400).json({ message: err })
}
const registerCallbackParams = {
callback_url: <my_callback_url>,
user_secret: "Test"
};
const readableTranscriptStream = new Readable();
readableTranscriptStream.push(req.file.buffer);
readableTranscriptStream.push(null);
const createJobParams = {
audio: readableTranscriptStream,
callback_url: <my_callback_url>,
content_type: req.file.mimetype,
events:"recognitions.completed_with_results",
inactivity_timeout: -1
};
speechToText.createJob(createJobParams)
.then(recognitionJob => {
console.log(recognitionJob);
})
.catch(err => {
console.log('error:', err);
});
})
我返回的错误是:
error:{
Error: Response not received. Body of error is HTTP ClientRequest object
at formatError (/app/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:111:17 )
at /app/node_modules/ibm-cloud-sdk-core/lib/requestwrapper.js:259:19 at process._tickCallback (internal/process/next_tick.js:68:7 )
message:'Response not received. Body of error is HTTP ClientRequest object',
body:Writable {
_writableState:WritableState {
objectMode:false,
highWaterMark:16384,
finalCalled:false,
needDrain:false,
ending:false,
ended:false,
finished:false,
destroyed:false,
decodeStrings:true,
defaultEncoding:'utf8',
length:0,
writing:false,
corked:0,
sync:true,
bufferProcessing:false,
onwrite:[
Function:bound onwrite
],
writecb:null,
writelen:0,
bufferedRequest:null,
lastBufferedRequest:null,
pendingcb:0,
prefinished:false,
errorEmitted:false,
emitClose:true,
bufferedRequestCount:0,
corkedRequestsFree:[
Object
]
},
writable:true,
_events:[
Object:null prototype
] {
response:[
Function:handleResponse
],
error:[
Function:handleRequestError
]
},
_eventsCount:2,
_maxListeners:undefined,
_options:{
maxRedirects:21,
maxBodyLength:10485760,
protocol:'https:',
path:'/speech-to-text/api/v1/recognitions?callback_url=<my_callback_url>&events=recognitions.completed_with_results&inactivity_timeout=-1',
method:'post',
headers:[
Object
],
agent:[
Agent
],
auth:undefined,
hostname:'stream.watsonplatform.net',
port:null,
nativeProtocols:[
Object
],
pathname:'/speech-to-text/api/v1/recognitions',
search:'?callback_url=<my_callback_url>&events=recognitions.completed_with_results&inactivity_timeout=-1'
},
_ended:false,
_ending:true,
_redirectCount:0,
_redirects:[
],
_requestBodyLength:0,
_requestBodyBuffers:[
],
_onNativeResponse:[
Function
],
_currentRequest:ClientRequest {
_events:[
Object
],
_eventsCount:6,
_maxListeners:undefined,
output:[
],
outputEncodings:[
],
outputCallbacks:[
],
outputSize:0,
writable:true,
_last:true,
chunkedEncoding:false,
shouldKeepAlive:false,
useChunkedEncodingByDefault:true,
sendDate:false,
_removedConnection:false,
_removedContLen:false,
_removedTE:false,
_contentLength:null,
_hasBody:true,
_trailer:'',
finished:false,
_headerSent:false,
socket:null,
connection:null,
_header:null,
_onPendingData:[
Function:noopPendingOutput
],
agent:[
Agent
],
socketPath:undefined,
timeout:undefined,
method:'POST',
path:'/speech-to-text/api/v1/recognitions?callback_url=<my_callback_url>&events=recognitions.completed_with_results&inactivity_timeout=-1',
_ended:false,
res:null,
aborted:1558070725953,
timeoutCb:null,
upgradeOrConnect:false,
parser:null,
maxHeadersCount:null,
_redirectable:[
Circular
],
[
Symbol(isCorked)
]:false,
[
Symbol(outHeadersKey)
]:[
Object
]
},
_currentUrl:'https://stream.watsonplatform.net/speech-to-text/api/v1/recognitions?callback_url=<my_callback_url>&events=recognitions.completed_with_results&inactivity_timeout=-1'
}
}
限制为 1GB,请确保您在提交时使用的是 Chunked 传输编码,这是输送大文件时常见的错误原因。 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding
尝试在实例化 SpeechToText 时添加 maxContentLength: Infinity
作为选项
const speechToText = new SpeechToTextV1({
username: 'user',
password: 'pass',
version: '2019-01-01',
maxContentLength: Infinity,
});