Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
gcsUri,
model,
encoding,
sampleRateHertz,
languageCode
) {
// [START speech_transcribe_model_selection_gcs]
// Imports the Google Cloud client library for Beta API
/**
* TODO(developer): Update client library import to use new
* version of API when desired features become available
*/
const speech = require('@google-cloud/speech').v1p1beta1;
// Creates a client
const client = new speech.SpeechClient();
/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const gcsUri = 'gs://my-bucket/audio.raw';
// const model = 'Model to use, e.g. phone_call, video, default';
// const encoding = 'Encoding of the audio file, e.g. LINEAR16';
// const sampleRateHertz = 16000;
// const languageCode = 'BCP-47 language code, e.g. en-US';
const config = {
encoding: encoding,
sampleRateHertz: sampleRateHertz,
languageCode: languageCode,
model: model,
};
async function syncRecognizeWithMultiChannel(fileName) {
// [START speech_transcribe_multichannel]
const fs = require('fs');
// Imports the Google Cloud client library
const speech = require('@google-cloud/speech').v1;
// Creates a client
const client = new speech.SpeechClient();
/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const fileName = 'Local path to audio file, e.g. /path/to/audio.raw';
const config = {
encoding: `LINEAR16`,
languageCode: `en-US`,
audioChannelCount: 2,
enableSeparateRecognitionPerChannel: true,
};
const audio = {
content: fs.readFileSync(fileName).toString('base64'),
};
async function syncRecognizeGCS(
gcsUri,
encoding,
sampleRateHertz,
languageCode
) {
// [START speech_transcribe_sync_gcs]
// 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 gcsUri = 'gs://my-bucket/audio.raw';
// const encoding = 'Encoding of the audio file, e.g. LINEAR16';
// const sampleRateHertz = 16000;
// const languageCode = 'BCP-47 language code, e.g. en-US';
const config = {
encoding: encoding,
sampleRateHertz: sampleRateHertz,
languageCode: languageCode,
};
const audio = {
uri: gcsUri,
function sampleRecognize(sampleRateHertz, languageCode, phrase, uriPath) {
const client = new speech.SpeechClient();
// const sampleRateHertz = 24000;
// const languageCode = 'en-US';
// const phrase = '$TIME';
// const uriPath = 'gs://cloud-samples-data/speech/time.mp3';
const encoding = 'MP3';
const phrases = [phrase];
const speechContextsElement = {
phrases: phrases,
};
const speechContexts = [speechContextsElement];
const config = {
encoding: encoding,
sampleRateHertz: sampleRateHertz,
languageCode: languageCode,
speechContexts: speechContexts,
};
// @ts-check
const Discord = require('discord.js')
const fs = require('fs')
const execFile = require('child_process').execFile
const config = JSON.parse(
fs.readFileSync(require.resolve('./discord.config.json'), 'utf8')
)
// @ts-ignore
const speech = require('@google-cloud/speech').v1p1beta1
const speechClient = new speech.SpeechClient({
keyFilename: 'google-cloud.credentials.json'
})
// This is our logger.
const pino = require('pino')({
prettyPrint: true,
level: 'trace'
})
// Crash when something unexpected happens.
// Let a process manager (e.g. pm2 or Docker) restart it.
process.on('unhandledRejection', up => {
throw up
})
// Keep track of billed usage.
async function syncRecognizeWithMultiChannelGCS(gcsUri) {
// [START speech_transcribe_multichannel_gcs]
const speech = require('@google-cloud/speech').v1;
// Creates a client
const client = new speech.SpeechClient();
const config = {
encoding: 'LINEAR16',
languageCode: `en-US`,
audioChannelCount: 2,
enableSeparateRecognitionPerChannel: true,
};
const audio = {
uri: gcsUri,
};
const request = {
config: config,
audio: audio,
};
async function speechTranscribeMultilangGCS(gcsUri) {
// [START speech_transcribe_multilanguage_gcs_beta]
// Imports the Google Cloud client library
const speech = require('@google-cloud/speech').v1p1beta1;
// Creates a client
const client = new speech.SpeechClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const uri = path to GCS audio file e.g. `gs:/bucket/audio.wav`;
const config = {
encoding: 'LINEAR16',
sampleRateHertz: 44100,
languageCode: `en-US`,
alternativeLanguageCodes: [`es-ES`, `en-US`],
};
const audio = {
uri: gcsUri,
};
function streamingMicRecognize(opts) {
const client = new speech.SpeechClient()
const spinner = ora('Initializing...').start()
const request = {
config: {
encoding: 'LINEAR16',
sampleRateHertz: 16000,
languageCode: opts.th ? 'th' : 'en-US',
model: opts.th ? 'default' : 'video',
useEnhanced: true,
enableAutomaticPunctuation: true,
alternativeLanguageCodes: opts.th ? ['en-US'] : []
},
interimResults: true
}
let expireTime
function updateSpinner() {