I am trying to use Amazon Transcribe Streaming Service with a http2 request from Node.js, Here is the documentation links that I am following Streaming request format. According to this document end point is https://transcribe-streaming.<'region'>.amazonaws.com, but making a request to this url gives url not found error. But in the Java Example found end point as https://transcribestreaming.''.amazonaws.com, so making a request to this url does not give any error or response back. I am trying from us-east-1 region.
Here is the code I am trying with.
const http2 = require('http2');
var aws4 = require('aws4');
var opts = {
service: 'transcribe',
region: 'us-east-1',
path: '/stream-transcription',
headers:{
'content-type': 'application/json',
'x-amz-target': 'com.amazonaws.transcribe.Transcribe.StartStreamTranscription'
}
}
var urlObj = aws4.sign(opts, {accessKeyId: '<access key>', secretAccessKey: '<aws secret>'});
const client = http2.connect('https://transcribestreaming.<region>.amazonaws.com');
client.on('error', function(err){
console.error("error in request ",err);
});
const req = client.request({
':method': 'POST',
':path': '/stream-transcription',
'authorization': urlObj.headers.Authorization,
'content-type': 'application/json',
'x-amz-content-sha256': 'STREAMING-AWS4-HMAC-SHA256-EVENTS',
'x-amz-target': 'com.amazonaws.transcribe.Transcribe.StartStreamTranscription',
'x-amz-date': urlObj['headers']['X-Amz-Date'],
'x-amz-transcribe-language-code': 'en-US',
'x-amz-transcribe-media-encoding': 'pcm',
'x-amz-transcribe-sample-rate': 44100
});
req.on('response', (headers, flags) => {
for (const name in headers) {
console.log(`${name}: ${headers[name]}`);
}
});
let data = '';
req.on('data', (chunk) => { data += chunk; });
req.on('end', () => {
console.log(`\n${data}`);
client.close();
});
req.end();
Can anyone point out what I am missing here. I couldn't find any examples implementing this with HTTP/2 either.
Update: Changing the Content-type to application/json came back with response status 200 but with following exception:
`{"Output":{"__type":"com.amazon.coral.service#SerializationException"},"Version":"1.0"}`
Update (April-22-2019):
req.setEncoding('utf8');
req.write(audioBlob);
var audioBlob = new Buffer(JSON.stringify({
"AudioStream": {
"AudioEvent": {
"AudioChunk": audioBufferData
}
}
Before ending the request I am adding a "audioblod" as payload by serializing. My "audioBufferData" is in raw PCM audio format from browser. I see from documentation payload has to be encoded to "Event Stream Encoding", but couldn't figure out how to implement it.
So with out this event stream encoding currently i am getting this following exception with 200 response status.
{"Output":{"__type":"com.amazon.coral.service#UnknownOperationException"},"Version":"1.0"}
from Amazon Transcribe Streaming service request in Node.js with Http/2 gives no response
Tem doc para PHP?
ReplyDelete