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

To help you get started, we’ve selected a few @google-cloud/text-to-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
}
        if (config.voiceName) {
            let voiceName = (config.voiceNameType === 'msg') ? helper.getByString(data, config.voiceName) : config.voiceName;
            parameters.voice.voice = voiceName;
        }
        if (config.ssmlGender) {
            let ssmlGender = (config.ssmlGenderType === 'msg') ? helper.getByString(data, config.ssmlGender) : config.ssmlGender;
            parameters.voice.ssmlGender = ssmlGender;
        }


        if (input.match(//ig)) parameters.input.ssml = input;
        else parameters.input.text = input;

        const texttospeech = require('@google-cloud/text-to-speech');
        let client = new texttospeech.v1beta1.TextToSpeechClient({credentials: node.auth.cred});
        let res = { audioContent: [] }
        
        client.synthesizeSpeech(parameters)
        .then((results) => {
            res.audioContent = (results[0] && results[0].audioContent) ? results[0].audioContent : [];

            if (!config.getVoices) return 1;
            else return client.listVoices({languageCode: parameters.voice.languageCode = languageCode})
        })
        .then((voices) => {
            if (voices !== 1 && voices[0] && voices[0].voices) {
                res.voices = (voices[0] && voices[0].voices) ? voices[0].voices : [];
            }
            helper.setByString(data, config.output || 'payload', res);
            return node.send(data);
        }).catch((err) => {

@google-cloud/text-to-speech

Cloud Text-to-Speech API client for Node.js

Apache-2.0
Latest version published 4 days ago

Package Health Score

92 / 100
Full package analysis