Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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({
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({
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)
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,
// 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 = "";
function main() {
const speechClient = new SpeechClient();
}
'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))
'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))