How to use the @google-cloud/speech.v1 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 NGRP / node-red-contrib-viseo / node-red-contrib-google-speech / google-speech-text.js View on Github external
let type = config.intype;
        if (type === 'url') parameters.audio.uri = input;
        else if (type === 'content') parameters.audio.content = input;
        else {
            try {
                let buffer = fs.readFileSync(input);
                parameters.audio.content = buffer.toString('base64');
            }
            catch(ex) {
                console.log(ex);
                helper.setByString(data, config.output || "payload", { error: ex });
                return node.send(data);
            }
        }
        const speech = require('@google-cloud/speech');
        let client = new speech.v1.SpeechClient({credentials: node.auth.cred});

        client.recognize(parameters).then((results) => {
            let alternatives = (results[0] && results[0].results && results[0].results[0] && results[0].results[0].alternatives) ? results[0].results[0].alternatives : [];
            helper.setByString(data, config.output || 'payload', { alternatives: alternatives });
            node.send(data);
        }).catch((err) => { 
            console.log(err);
            helper.setByString(data, config.output || 'payload', { error: err });
            node.send(data);
        });
        
    }

    // TTS
    else {
github googleapis / nodejs-speech / samples / recognize.js View on Github external
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 = {
github mimming / zero-to-app-universal-translator / js / functions / index.js View on Github external
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.


const functions = require('firebase-functions');
const Speech = require('@google-cloud/speech');
const speech = Speech({keyFilename: "service-account-credentials.json"});
const Translate = require('@google-cloud/translate');
const translate = Translate({keyFilename: "service-account-credentials.json"});
const Encoding = Speech.v1.types.RecognitionConfig.AudioEncoding;

function getLanguageWithoutLocale(languageCode) {
    if (languageCode.indexOf("-") >= 0) {
        return languageCode.substring(0, languageCode.indexOf("-"));
    }
    return languageCode;
}

exports.onUpload = functions.database
    .ref("/uploads/{uploadId}")
    .onWrite((event) => {
        let data = event.data.val();
        let language = data.language ? data.language : "en";
        let sampleRate = data.sampleRate ? data.sampleRate : 16000;
        let encoding = data.encoding == "FLAC" ? Encoding.FLAC : Encoding.AMR;
github mimming / zero-to-app-universal-translator / js / functions / index.start.js View on Github external
//  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.

const functions = require('firebase-functions');
const Speech = require('@google-cloud/speech');
const speech = Speech({keyFilename: "service-account-credentials.json"});
const Translate = require('@google-cloud/translate');
const translate = Translate({keyFilename: "service-account-credentials.json"});
const Encoding = Speech.v1.types.RecognitionConfig.AudioEncoding;

function getLanguageWithoutLocale(languageCode) {
    if (languageCode.indexOf("-") >= 0) {
        return languageCode.substring(0, languageCode.indexOf("-"));
    }
    return languageCode;
}