Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {
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 = {
//
// 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;
// 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;
}