Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Most simple example I could find for ongoing listening of microphone using the google cloud speech api.
// Imports the Google Cloud client library
const speech = require('@google-cloud/speech')
const record = require('node-record-lpcm16')
const client = new speech.SpeechClient({
// generated service key downloaded from cloud console
credentials: require('./admin-key.json')
const sampleRateHertz = 16000
sampleRateHertz: sampleRateHertz,
threshold: 0,
verbose: false,
recordProgram: 'rec'
// Other options, see
.on('error', console.error)
interimResults: true,
config: {
encoding: 'LINEAR16',
languageCode: 'sv-SE',
.on('error', console.error)
.on('data', data =>
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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.