I've been trying to setup a node service for streaming live audio to the Google Speech API, but I've hit a problem that I think might be authentication related.
The service is written in node using Express and BinaryServer, I'm receiving data without any problems (and have been able to save it to the local disk, but that section of code isn't in the below example), but when I try to submit to the Google API I don't receive anything back (Although if I remove the keyFileName from the request then I get "Error: Could not load the default credentials" which is fair enough because I'm running outside the GCE)
var express = require("express");
var app = express();
var port = 54180;
var BinaryServer = require('binaryjs').BinaryServer;
var server = BinaryServer({
port: port
});
app.listen(port, function () {
console.log('server open on port ' + port);
});
binaryServer = BinaryServer({
port: 9001
});
binaryServer.on('connection', function (client) {
console.log('Binary Server connection started');
client.on('stream', function (stream, meta) {
console.log('>>>Incoming audio stream');
var speech = require('@google-cloud/speech')({
projectId: 'MYPROJECT-1234'
//keyFilename: '/config/KeyFile.json'
});
const request = {
config: {
encoding: 'LINEAR16',
sampleRate: 16000
},
singleUtterance: false,
interimResults: true
};
// Create a recognize stream
const recognizeStream = speech.createRecognizeStream(request)
.on('error', function (error) {
console.log('Error');
console.log(error)
})
.on('data', function (data) {
console.log('Data');
console.log(data);
});
// Send the microphone input to the Speech API
stream.pipe(recognizeStream);
stream.on('end', function () {
fileWriter.end();
recognizeStream.end();
console.log('||| Audio stream ended');
});
});
});
I'll also admit this is the first time I've tried to re-pipe to another API, so it could be that I've screwed that part up, but the default credentials message makes me think it's piping OK and it's just rejecting my request without returning a reason.
Can anyone spot what I'm getting wrong?
Cheers.