Skip to content

Audio Stream Timing Out Instantly #626

@dhanud5

Description

@dhanud5

So I'm trying to get Google speech to text to listen to my microphone for transcription. I am using windows and sox. System variable path is set and all google cloud accounts are active. My problem is that the service stops right as it starts. The max amount of time it ran for was around 50ms. Here's a screencap of what I get in the command prompt.
image

Here's my code:

const express = require('express');
const app = express();
const http = require('http');
const server = require('http').createServer(app);
var io = require('socket.io')(server);

const fs = require('fs');

const LISTEN_PORT = 8080;

var transText;

server.listen(LISTEN_PORT);
app.use(express.static(__dirname + '/public'));

console.log("Listening on port: " + LISTEN_PORT);

app.get( '/', function( req, res ){
res.sendFile( __dirname + '/public/index.html' );
});

//////////////////////////////////////////////////////////////////////

// Creates a client
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();

const encoding = 'LINEAR16';
const sampleRateHertz = 16000;
const languageCode = 'en-US';

const request = {
config: {
encoding: encoding,
sampleRateHertz: sampleRateHertz,
languageCode: languageCode,
},
interimResults: true, // 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 =>
console.log(
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: 16000,
// Other options, see https://www.npmjs.com/package/node-record-lpcm16#options
verbose: true,
recordProgram: 'sox', // Try also "arecord" or "sox"
silence: '1500000.0',
device: 'plughw:0,0',
})
.on('error', console.error)
.pipe(recognizeStream);

setTimeout(function () {
record.stop()
}, 10000)

console.log('Listening, press Ctrl+C to stop.');

//////////////////////////////////////////////////////////////////////////
io.on('connection', function(socket) {

    io.emit('transcription', transText);

});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions