Monday 25 February 2019

Help with Google-Cloud Speech API and Heroku events.js error

I'm trying to get a simple Google Cloud/Speech app running to convert my Mic audio to text. My index.js.belowvar app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); const record = require('node-record-lpcm16'); // Imports the Google Cloud client library const speech = require('@google-cloud/speech'); // Creates a client const client = new speech.SpeechClient(); /** * TODO(developer): Uncomment the following lines before running the sample. */ const encoding = 'LINEAR16'; const sampleRateHertz = 16000; const languageCode = 'en-US'; const request = { config: { encoding: encoding, sampleRateHertz: sampleRateHertz, languageCode: languageCode, }, interimResults: false, // If you want interim results, set this to true }; // Create a recognize stream const recognizeStream = client .streamingRecognize(request) .on('error', console.error) .on('data', data => process.stdout.write( data.results[0] && data.results[0].alternatives[0] ? `Transcription: ${data.results[0].alternatives[0].transcript}\n` : `\n\nReached transcription time limit, press Ctrl+C\n` ) ); // Start recording and send the microphone input to the Speech API record .start({ sampleRateHertz: sampleRateHertz, threshold: 0, // Other options, see https://www.npmjs.com/package/node-record-lpcm16#options verbose: false, recordProgram: 'rec', // Try also "arecord" or "sox" silence: '10.0', }) .on('error', console.error) .pipe(recognizeStream); console.log('Listening, press Ctrl+C to stop.'); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); io.on('connection', function(socket){ console.log('a user connected'); }); http.listen(3000, function(){ console.log('listening on *:3000'); }); If I run the above code locally, it works perfectly. If I remove all the Google Speech code, the server runs fine. But when using the above (Same as the Docs) Heroku spins up then throws an error.2019-02-25T09:07:38.000000+00:00 app[api]: Build succeeded 2019-02-25T09:07:39.926417+00:00 app[web.1]: 2019-02-25T09:07:39.926435+00:00 app[web.1]: > socket-chat-example@0.0.1 start /app 2019-02-25T09:07:39.926437+00:00 app[web.1]: > node index.js 2019-02-25T09:07:39.926439+00:00 app[web.1]: 2019-02-25T09:07:40.617413+00:00 app[web.1]: Listening, press Ctrl+C to stop. 2019-02-25T09:07:40.626395+00:00 app[web.1]: events.js:174 2019-02-25T09:07:40.626399+00:00 app[web.1]: throw er; // Unhandled 'error' event 2019-02-25T09:07:40.626401+00:00 app[web.1]: ^ 2019-02-25T09:07:40.626403+00:00 app[web.1]: 2019-02-25T09:07:40.626405+00:00 app[web.1]: Error: spawn rec ENOENT 2019-02-25T09:07:40.626407+00:00 app[web.1]: at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19) 2019-02-25T09:07:40.626410+00:00 app[web.1]: at onErrorNT (internal/child_process.js:415:16) 2019-02-25T09:07:40.626412+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19) 2019-02-25T09:07:40.626414+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:745:11) 2019-02-25T09:07:40.626416+00:00 app[web.1]: at startup (internal/bootstrap/node.js:283:19) 2019-02-25T09:07:40.626417+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3) 2019-02-25T09:07:40.626419+00:00 app[web.1]: Emitted 'error' event at: 2019-02-25T09:07:40.626421+00:00 app[web.1]: at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12) 2019-02-25T09:07:40.626423+00:00 app[web.1]: at onErrorNT (internal/child_process.js:415:16) 2019-02-25T09:07:40.626425+00:00 app[web.1]: [... lines matching original stack trace ...] 2019-02-25T09:07:40.626427+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3) 2019-02-25T09:07:40.636937+00:00 app[web.1]: npm ERR! code ELIFECYCLE I have all the Google Cloud credentials set up as environment variables in Heroku and they seem to be working fine.Any help is much appreciated.Cheers

Submitted February 25, 2019 at 09:49AM by CyrisXD

No comments:

Post a Comment