How to use the @google-cloud/speech.SpeechClient function in @google-cloud/speech

To help you get started, we’ve selected a few @google-cloud/speech examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-speech / samples / MicrophoneStream.js View on Github external
// Imports the Google Cloud client library
  const speech = require('@google-cloud/speech');

  const config = {
    encoding: encoding,
    sampleRateHertz: sampleRateHertz,
    languageCode: languageCode,
  };

  const request = {
    config,
    interimResults: false, //Get interim results from stream
  };

  // Creates a client
  const client = new speech.SpeechClient();

  // 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
  recorder
    .record({
github googleapis / nodejs-speech / samples / continuousMicrophoneStream.js View on Github external
const config = {
    encoding: encoding,
    sampleRateHertz: sampleRateHertz,
    languageCode: languageCode,
  };

  const request = {
    config,
    interimResults: true, //Get interim results from stream
  };

  const STREAMING_LIMIT = 55000;

  // Create a client
  const client = new speech.SpeechClient();

  function startStream() {
    // Initiate (Reinitiate) a recognize stream
    const recognizeStream = client
      .streamingRecognize(request)
      .on('error', console.error)
      .on('data', data => {
        process.stdout.clearLine();
        process.stdout.cursorTo(0);
        process.stdout.write(data.results[0].alternatives[0].transcript);
        if (data.results[0].isFinal) process.stdout.write('\n');
      });

    // Start recording and send the microphone input to the Speech API
    record
      .start({
github syntithenai / hermod / src / HermodGoogleAsrService.js View on Github external
getDetector(siteId) {
		
		// Google Speech Client
		const client = new speech.SpeechClient();
		const encoding = 'LINEAR16';
		const sampleRateHertz = 16000;
		const languageCode = 'en-AU';
		const request = {
		  config: {
			encoding: encoding,
			sampleRateHertz: sampleRateHertz,
			languageCode: languageCode,
		  },
		  interimResults: false, // If you want interim results, set this to true
		};	
		
		// Stream the audio to the Google Cloud Speech API
		var detector = client
		.streamingRecognize(request)
		.on('error', console.log)
github googleapis / nodejs-speech / samples / speech-to-text-to-dlp.js View on Github external
async function transcribeSpeech() {
    // Creates a client
    const speechClient = new speech.SpeechClient();

    /**
     *  TODO(developer): Uncomment the following lines before running the sample.
     */

    //const filename = './resources/sallybrown.flac';
    //const encoding = 'FLAC';
    //const sampleRateHertz = 16000;
    //const languageCode = 'en-US';

    // Reads a local audio file and converts it to base64
    const file = fs.readFileSync(filename);
    const audioBytes = file.toString('base64');

    const audio = {
      content: audioBytes,
github traumverloren / speech-to-image-necklace / app.js View on Github external
// Check all 10 link items if jpeg, jpg, png, gif.
      const imageURLs = results.items
        .map(item => item.link)
        .filter(url => validImageFormats.some(format => url.includes(format)));
      // Set currentImageURL randomly from that filtered array
      currentImageURL = imageURLs[Math.floor(Math.random() * imageURLs.length)];
    }
  });
};

// ----- Speech to text stuff -----
const speech = require("@google-cloud/speech");
const fs = require("fs");

// Creates a speech client
const client = new speech.SpeechClient();
const record = require("node-record-lpcm16");

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

const speechRequest = {
  config: {
    encoding,
    sampleRateHertz,
    languageCode
  },
  interimResults: true // If you want interim results, set this to true
};

let currentWord = "";
github evancohen / sonus / examples / example.js View on Github external
'use strict'

const ROOT_DIR = __dirname + '/../'
const Sonus = require(ROOT_DIR + 'index.js') //require('sonus')
const speech = require('@google-cloud/speech')
const client = new speech.SpeechClient({
  projectId: 'streaming-speech-sample',
  keyFilename: ROOT_DIR +  'keyfile.json'
})

const hotwords = [{ file: ROOT_DIR + 'resources/sonus.pmdl', hotword: 'sonus' }]
const language = "en-US"

//recordProgram can also be 'arecord' which works much better on the Pi and low power devices
const sonus = Sonus.init({ hotwords, language, recordProgram: "rec" }, client)

Sonus.start(sonus)
console.log('Say "' + hotwords[0].hotword + '"...')

sonus.on('hotword', (index, keyword) => console.log("!" + keyword))

sonus.on('partial-result', result => console.log("Partial", result))
github evancohen / sonus / examples / example.js View on Github external
'use strict'

const ROOT_DIR = __dirname + '/../'
const Sonus = require(ROOT_DIR + 'index.js')
const speech = require('@google-cloud/speech')

const client = new speech.SpeechClient({
  projectId: 'streaming-speech-sample',
  keyFilename: ROOT_DIR + 'keyfile.json'
})

const hotwords = [{ file: ROOT_DIR + 'resources/sonus.pmdl', hotword: 'sonus' }]
const language = "en-US"

//recordProgram can also be 'arecord' which works much better on the Pi and low power devices
const sonus = Sonus.init({ hotwords, language, recordProgram: "rec" }, client)

Sonus.start(sonus)
console.log('Say "' + hotwords[0].hotword + '"...')

sonus.on('hotword', (index, keyword) => console.log("!" + keyword))

sonus.on('partial-result', result => console.log("Partial", result))

@google-cloud/speech

Cloud Speech Client Library for Node.js

Apache-2.0
Latest version published 1 month ago

Package Health Score

92 / 100
Full package analysis