Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const audioUtils = require('./audioUtils'); // for encoding audio data as PCM
const crypto = require('crypto'); // tot sign our pre-signed URL
const v4 = require('./aws-signature-v4'); // to generate our pre-signed URL
const marshaller = require("@aws-sdk/eventstream-marshaller"); // for converting binary event stream messages to and from JSON
const util_utf8_node = require("@aws-sdk/util-utf8-node"); // utilities for encoding and decoding UTF8
const mic = require('microphone-stream'); // collect microphone input as a stream of raw bytes
// our converter between binary event streams messages and JSON
const eventStreamMarshaller = new marshaller.EventStreamMarshaller(util_utf8_node.toUtf8, util_utf8_node.fromUtf8);
// our global variables for managing state
let languageCode;
let region;
let sampleRate;
let transcription = "";
let socket;
let micStream;
let socketError = false;
let transcribeException = false;
// check to see if the browser allows mic access
if (!window.navigator.mediaDevices.getUserMedia) {
// Use our helper method to show an error on the page
showError('We support the latest versions of Chrome, Firefox, Safari, and Edge. Update your browser and try your request again.');
constructor(toUtf8: Encoder, fromUtf8: Decoder) {
this.eventMarshaller = new EventMarshaller(toUtf8, fromUtf8);
}
deserialize(
import { AbstractConvertPredictionsProvider } from "../types/Providers/AbstractConvertPredictionsProvider";
import * as Translate from 'aws-sdk/clients/translate';
import * as TextToSpeech from 'aws-sdk/clients/polly';
import {
TranslateTextInput, TextToSpeechInput,
SpeechToTextInput, TranslateTextOutput, TextToSpeechOutput,
SpeechToTextOutput, isBytesSource} from "../types";
import { Credentials, ConsoleLogger as Logger, Signer } from '@aws-amplify/core';
import { EventStreamMarshaller, MessageHeaderValue } from '@aws-sdk/eventstream-marshaller';
import { fromUtf8, toUtf8 } from '@aws-sdk/util-utf8-node';
const logger = new Logger('AmazonAIConvertPredictionsProvider');
const eventBuilder = new EventStreamMarshaller(toUtf8, fromUtf8);
export default class AmazonAIConvertPredictionsProvider extends AbstractConvertPredictionsProvider {
private translate: Translate;
private textToSpeech: TextToSpeech;
constructor() {
super();
}
getProviderName() {
return "AmazonAIConvertPredictionsProvider";
}
protected translateText(input: TranslateTextInput): Promise {
logger.debug("Starting translation");
return new Promise(async (res, rej) => {