repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
project-lakechain | github_2023 | awslabs | typescript | LanceDbLayer.arm64 | static arm64(scope: Construct, id: string): lambda.LayerVersion {
const architecture = lambda.Architecture.ARM_64;
// The Docker image to use to build the layer.
const image = cdk.DockerImage.fromRegistry(
'public.ecr.aws/sam/build-nodejs18.x:1.124.0-arm64'
);
// Builds the LanceDB library for the target architecture
// and outputs the result in the /asset-output directory.
const layerAsset = new s3assets.Asset(scope, `Asset-${id}`, {
path: path.join(__dirname),
bundling: {
image,
platform: architecture.dockerPlatform,
command: [
'/bin/bash',
'-c',
'npm install --prefix=/asset-output/nodejs --arch=arm64 --platform=linux vectordb @lancedb/vectordb-linux-arm64-gnu'
],
outputType: cdk.BundlingOutput.AUTO_DISCOVER,
network: 'host',
user: 'root'
}
});
return (new lambda.LayerVersion(scope, id, {
description: 'Provides a lambda layer for LanceDB.',
code: lambda.Code.fromBucket(
layerAsset.bucket,
layerAsset.s3ObjectKey
),
compatibleRuntimes: [
lambda.Runtime.NODEJS_18_X
],
compatibleArchitectures: [
lambda.Architecture.ARM_64
]
}));
} | /**
* @param scope the construct scope.
* @param id the construct identifier.
* @returns a lambda layer version for the LanceDB library
* compiled for ARM64.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/layers/src/lancedb/index.ts#L34-L73 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | LanceDbLayer.x64 | static x64(scope: Construct, id: string): lambda.LayerVersion {
const architecture = lambda.Architecture.X86_64;
// The Docker image to use to build the layer.
const image = cdk.DockerImage.fromRegistry(
'public.ecr.aws/sam/build-nodejs18.x:1.124.0-x86_64'
);
// Builds the LanceDB library for the target architecture
// and outputs the result in the /asset-output directory.
const layerAsset = new s3assets.Asset(scope, `Asset-${id}`, {
path: path.join(__dirname),
bundling: {
image,
platform: architecture.dockerPlatform,
command: [
'/bin/bash',
'-c',
'npm install --prefix=/asset-output/nodejs --arch=x64 --platform=linux vectordb @lancedb/vectordb-linux-x64-gnu'
],
outputType: cdk.BundlingOutput.AUTO_DISCOVER,
network: 'host',
user: 'root'
}
});
return (new lambda.LayerVersion(scope, id, {
description: 'Provides a lambda layer for LanceDB.',
code: lambda.Code.fromBucket(
layerAsset.bucket,
layerAsset.s3ObjectKey
),
compatibleRuntimes: [
lambda.Runtime.NODEJS_18_X
],
compatibleArchitectures: [
lambda.Architecture.X86_64
]
}));
} | /**
* @param scope the construct scope.
* @param id the construct identifier.
* @returns a lambda layer version for the LanceDB library
* compiled for X64.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/layers/src/lancedb/index.ts#L81-L120 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | MediaInfoLayer.fromArch | static fromArch(
scope: Construct,
id: string,
architecture: lambda.Architecture,
version: string = DEFAULT_MEDIA_INFO_VERSION
): lambda.LayerVersion {
const archName = architecture === lambda.Architecture.ARM_64 ? 'arm64' : 'x64';
// The Docker image to use to build the layer.
const image = cdk.DockerImage.fromRegistry(
`public.ecr.aws/sam/build-python3.11:1.124.0-${architecture.name}`
);
// Build the layer.
const layerAsset = new s3assets.Asset(scope, `Asset-${id}`, {
path: path.join(__dirname),
assetHashType: cdk.AssetHashType.OUTPUT,
bundling: {
image,
platform: architecture.dockerPlatform,
command: [
'/bin/bash',
'-c', [
'yum install -y wget unzip',
`wget https://mediaarea.net/download/binary/libmediainfo0/${version}/MediaInfo_DLL_${version}_Lambda_${archName}.zip`,
`unzip -o MediaInfo_DLL_${version}_Lambda_${archName}.zip`,
'mkdir -p /asset-output/python',
'cp -L lib/* /asset-output/python'
].join(' && ')
],
outputType: cdk.BundlingOutput.AUTO_DISCOVER,
network: 'host',
user: 'root'
}
});
// Create the layer from the build output.
return (new lambda.LayerVersion(scope, id, {
description: 'Provides a lambda layer for the MediaInfo library.',
code: lambda.Code.fromBucket(
layerAsset.bucket,
layerAsset.s3ObjectKey
),
compatibleRuntimes: [
lambda.Runtime.PYTHON_3_11,
lambda.Runtime.PYTHON_3_10,
lambda.Runtime.PYTHON_3_9,
lambda.Runtime.PYTHON_3_8
],
compatibleArchitectures: [architecture]
}));
} | /**
* @param scope the construct scope.
* @param id the construct identifier.
* @param architecture the architecture to build the layer for.
* @returns a lambda layer version for the MediaInfo library
* compiled for the given architecture.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/layers/src/mediainfo/index.ts#L40-L91 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | MediaInfoLayer.x64 | static x64(scope: Construct, id: string, version: string = DEFAULT_MEDIA_INFO_VERSION): lambda.LayerVersion {
return (MediaInfoLayer.fromArch(scope, id, lambda.Architecture.X86_64, version));
} | /**
* @param scope the construct scope.
* @param id the construct identifier.
* @returns a lambda layer version for the MediaInfo library
* compiled for x64.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/layers/src/mediainfo/index.ts#L99-L101 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | MediaInfoLayer.arm64 | static arm64(scope: Construct, id: string, version: string = DEFAULT_MEDIA_INFO_VERSION): lambda.LayerVersion {
return (MediaInfoLayer.fromArch(scope, id, lambda.Architecture.ARM_64, version));
} | /**
* @param scope the construct scope.
* @param id the construct identifier.
* @returns a lambda layer version for the MediaInfo library
* compiled for ARM64.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/layers/src/mediainfo/index.ts#L109-L111 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PowerToolsPythonLayer.x64 | static x64(scope: Construct, id: string, version = 60): lambda.ILayerVersion {
return (lambda.LayerVersion.fromLayerVersionArn(scope, id,
`arn:aws:lambda:${cdk.Aws.REGION}:017000801446:layer:AWSLambdaPowertoolsPythonV2:${version}`
));
} | /**
* @param scope the construct scope.
* @param id the construct identifier.
* @param version the layer version to use.
* @returns a lambda layer version for the AWS PowerTools Python library
* compiled for x64.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/layers/src/powertools/index.ts#L33-L37 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PowerToolsPythonLayer.arm64 | static arm64(scope: Construct, id: string, version = 60): lambda.ILayerVersion {
return (lambda.LayerVersion.fromLayerVersionArn(scope, id,
`arn:aws:lambda:${cdk.Aws.REGION}:017000801446:layer:AWSLambdaPowertoolsPythonV2-Arm64:${version}`
));
} | /**
* @param scope the construct scope.
* @param id the construct identifier.
* @param version the layer version to use.
* @returns a lambda layer version for the AWS PowerTools Python library
* compiled for ARM64.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/layers/src/powertools/index.ts#L46-L50 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PowerToolsTypescriptLayer.layer | static layer(scope: Construct, id: string, version = 27): lambda.ILayerVersion {
return (lambda.LayerVersion.fromLayerVersionArn(scope, id,
`arn:aws:lambda:${cdk.Aws.REGION}:094274105915:layer:AWSLambdaPowertoolsTypeScript:${version}`
));
} | /**
* @param scope the construct scope.
* @param id the construct identifier.
* @returns a lambda layer version for the AWS PowerTools Typescript library.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/layers/src/powertools/index.ts#L63-L67 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PowerToolsLayer.python | static python() {
return (PowerToolsPythonLayer);
} | /**
* @returns a lambda layer version for the AWS Python PowerTools
* library, compatible with both x64 and ARM64 architectures.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/layers/src/powertools/index.ts#L80-L82 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PowerToolsLayer.typescript | static typescript() {
return (PowerToolsTypescriptLayer);
} | /**
* @returns a lambda layer version for the AWS Typescript PowerTools
* library.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/layers/src/powertools/index.ts#L88-L90 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | SharpLayer.arm64 | static arm64(scope: Construct, id: string): lambda.LayerVersion {
const architecture = lambda.Architecture.ARM_64;
// The Docker image to use to build the layer.
const image = cdk.DockerImage.fromRegistry(
'public.ecr.aws/sam/build-nodejs18.x:1.124.0-arm64'
);
// Builds the Sharp library for the target architecture
// and outputs the result in the /asset-output directory.
const layerAsset = new s3assets.Asset(scope, `Asset-${id}`, {
path: path.join(__dirname),
bundling: {
image,
platform: architecture.dockerPlatform,
command: [
'/bin/bash',
'-c',
'npm install --prefix=/asset-output/nodejs --arch=arm64 --platform=linux sharp'
],
outputType: cdk.BundlingOutput.AUTO_DISCOVER,
network: 'host',
user: 'root'
}
});
return (new lambda.LayerVersion(scope, id, {
description: 'Provides a lambda layer for the Sharp library.',
code: lambda.Code.fromBucket(
layerAsset.bucket,
layerAsset.s3ObjectKey
),
compatibleRuntimes: [
lambda.Runtime.NODEJS_18_X
],
compatibleArchitectures: [
lambda.Architecture.ARM_64
]
}));
} | /**
* @param scope the construct scope.
* @param id the construct identifier.
* @returns a lambda layer version for the Sharp library
* compiled for ARM64.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/layers/src/sharp/index.ts#L34-L73 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | AudioMetadataExtractorBuilder.build | public build(): AudioMetadataExtractor {
return (new AudioMetadataExtractor(
this.scope,
this.identifier, {
...this.props
}
));
} | /**
* @returns a new instance of the `AudioMetadataExtractor`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/audio-metadata-extractor/src/index.ts#L72-L79 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | AudioMetadataExtractor.constructor | constructor(scope: Construct, id: string, private props: MiddlewareProps) {
super(scope, id, description, {
...props,
queueVisibilityTimeout: cdk.Duration.seconds(
3 * PROCESSING_TIMEOUT.toSeconds()
)
});
///////////////////////////////////////////
/////// Processing Function ///////
///////////////////////////////////////////
// The lambda function.
this.processor = new node.NodejsFunction(this, 'Compute', {
description: 'A function extracting metadata from audio files.',
entry: path.resolve(__dirname, 'lambdas', 'metadata-extractor', 'index.js'),
vpc: this.props.vpc,
memorySize: this.props.maxMemorySize ?? DEFAULT_MEMORY_SIZE,
timeout: PROCESSING_TIMEOUT,
runtime: EXECUTION_RUNTIME,
architecture: lambda.Architecture.ARM_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
insightsVersion: this.props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
SNS_TARGET_TOPIC: this.eventBus.topicArn,
LAKECHAIN_CACHE_STORAGE: this.props.cacheStorage.id()
},
bundling: {
minify: true,
externalModules: [
'@aws-sdk/client-s3',
'@aws-sdk/client-sns'
]
}
});
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = this.processor.grantPrincipal;
// Plug the SQS queue into the lambda function.
this.processor.addEventSource(new sources.SqsEventSource(this.eventQueue, {
batchSize: props.batchSize ?? 5,
reportBatchItemFailures: true
}));
// Function permissions.
this.eventBus.grantPublish(this.processor);
super.bind();
} | /**
* Provider constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/audio-metadata-extractor/src/index.ts#L101-L158 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | AudioMetadataExtractor.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
// Since this middleware simply passes through the data
// from the previous middleware, we grant any subsequent
// middlewares in the pipeline read access to the
// data of all source middlewares.
for (const source of this.sources) {
source.grantReadProcessedDocuments(grantee);
}
return ({} as iam.Grant);
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/audio-metadata-extractor/src/index.ts#L164-L173 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | AudioMetadataExtractor.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'audio/mpeg',
'audio/mp4',
'audio/wav',
'audio/x-wav',
'audio/x-m4a',
'audio/ogg',
'audio/x-flac',
'audio/flac',
'audio/x-aiff',
'audio/aiff',
'audio/x-ms-wma',
'audio/x-matroska',
'audio/webm',
'audio/aac'
]);
} | /**
* @returns an array of mime-types supported as input
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/audio-metadata-extractor/src/index.ts#L179-L196 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | AudioMetadataExtractor.supportedOutputTypes | supportedOutputTypes(): string[] {
return (this.supportedInputTypes());
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/audio-metadata-extractor/src/index.ts#L202-L204 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | AudioMetadataExtractor.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/audio-metadata-extractor/src/index.ts#L210-L214 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | AudioMetadataExtractor.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/audio-metadata-extractor/src/index.ts#L223-L228 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getImage | const getImage = (picture: any) => {
return ({
type: picture.format,
data: picture.data.toString('base64')
});
}; | /**
* @param picture a picture object provided by the
* `music-metadata` library.
* @returns an image description object.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/audio-metadata-extractor/src/lambdas/metadata-extractor/get-metadata.ts#L31-L36 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | toFixed | const toFixed = (num: number, digits = 0, base = 10) => {
const pow = Math.pow(base, digits);
return (Math.round(num * pow) / pow);
}; | /**
* A small helper allowing
* @param num the number to convert into a decimal
* fixed digits number.
* @param digits the number of decimal digits to keep.
* @param base the base associated with the number.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/audio-metadata-extractor/src/lambdas/metadata-extractor/get-metadata.ts#L45-L48 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.handler | async handler(event: SQSEvent, _: Context): Promise<SQSBatchResponse> {
return (await processPartialResponse(
event,
(record: SQSRecord) => this.processEvent(
CloudEvent.from(JSON.parse(record.body))
),
processor
));
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/audio-metadata-extractor/src/lambdas/metadata-extractor/index.ts#L79-L87 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizerBuilder.constructor | constructor() {
super();
this.providerProps.voiceMapping = {};
} | /**
* Builder constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L58-L61 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizerBuilder.withLanguageOverride | public withLanguageOverride(language: BarkLanguage) {
this.providerProps.languageOverride = language;
return (this);
} | /**
* Specifies the language to assume the source
* document being written in.
* @param language the language to assume.
* @returns the builder itself.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L69-L72 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizerBuilder.withVoiceMapping | public withVoiceMapping(language: BarkLanguage, ...voiceArray: BarkVoice[]) {
const languageVoices = this.providerProps.voiceMapping![language];
// Verify that the voices match the given language.
const incompatibleVoices = voiceArray.filter(voice =>
!voices
.filter(voice => voice.LanguageCode === language)
.find(v => v.Id === voice)
);
// Throw an error if there are incompatible voices.
if (incompatibleVoices.length > 0) {
throw new Error(
`The following voices are not available for the language ${language}: ` +
`${incompatibleVoices.join(', ')}`
);
}
if (languageVoices) {
this.providerProps.voiceMapping![language] = [
...languageVoices,
...voiceArray
];
return (this);
}
this.providerProps.voiceMapping![language] = voiceArray;
return (this);
} | /**
* Specifies a mapping between a language and a voice descriptor.
* @param language the language to map.
* @param voice the voice descriptor to map.
* @see https://suno-ai.notion.site/8b8e8749ed514b0cbf3f699013548683?v=bc67cff786b04b50b3ceb756fd05f68c
* @returns the builder itself.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L81-L108 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizerBuilder.withTemperature | public withTemperature(temperature: number) {
this.providerProps.temperature = temperature;
return (this);
} | /**
* Specifies the temperature to pass to the Bark generative model
* when generating text to speech.
* @param temperature the temperature to use.
* @returns the builder itself.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L116-L119 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizerBuilder.withMaxInstances | public withMaxInstances(maxInstances: number) {
this.providerProps.maxInstances = maxInstances;
return (this);
} | /**
* The maximum amount of instances the
* cluster can have. Keep this number to
* a reasonable value to avoid over-provisioning
* the cluster.
* @param maxInstances the maximum amount of instances.
* @default 5
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L129-L132 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizerBuilder.build | public build(): BarkSynthesizer {
return (new BarkSynthesizer(
this.scope,
this.identifier, {
...this.providerProps as BarkSynthesizerProps,
...this.props
}
));
} | /**
* @returns a new instance of the `BarkSynthesizer`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L138-L146 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizer.constructor | constructor(scope: Construct, id: string, private props: BarkSynthesizerProps) {
super(scope, id, description, {
...props,
queueVisibilityTimeout: cdk.Duration.minutes(30)
});
// Validate the properties.
this.props = this.parse(BarkSynthesizerPropsSchema, props);
///////////////////////////////////////////
//////// Processing Storage ///////
///////////////////////////////////////////
this.storage = new CacheStorage(this, 'Storage', {
encryptionKey: this.props.kmsKey
});
///////////////////////////////////////////
///////// ECS Container /////////
///////////////////////////////////////////
// The configuration to use for GPU.
const configuration = getGpuConfiguration();
// The container image to provision the ECS tasks with.
const image = ecs.ContainerImage.fromDockerImageAsset(
new assets.DockerImageAsset(this, 'BarkImage', {
directory: path.resolve(__dirname, 'container'),
file: configuration.container.dockerFile,
platform: configuration.container.platform
})
);
// The environment variables to pass to the container.
const environment: {[key: string]: string} = {
POWERTOOLS_SERVICE_NAME: description.name,
PROCESSED_FILES_BUCKET: this.storage.id(),
TEMPERATURE: `${this.props.temperature}`,
HF_HOME: '/cache',
XDG_CACHE_HOME: '/cache',
VOICE_MAPPING: JSON.stringify(this.props.voiceMapping)
};
// Use the ECS container middleware pattern to create an
// auto-scaled ECS cluster, an EFS mounted on the cluster's tasks
// and all the components required to manage the cluster.
// This cluster supports both CPU and GPU instances.
const cluster = new EcsCluster(this, 'Cluster', {
vpc: this.props.vpc,
eventQueue: this.eventQueue,
eventBus: this.eventBus,
kmsKey: props.kmsKey,
logGroup: this.logGroup,
containerProps: {
image,
containerName: description.name,
cpuLimit: configuration.cpuLimit,
memoryLimitMiB: configuration.memoryLimitMiB,
gpuCount: configuration.gpuCount,
environment
},
autoScaling: {
minInstanceCapacity: 0,
maxInstanceCapacity: this.props.maxInstances,
maxTaskCapacity: this.props.maxInstances,
maxMessagesPerTask: 1
},
launchTemplateProps: {
instanceType: configuration.instanceType,
machineImage: configuration.machineImage,
ebsOptimized: true,
blockDevices: [{
deviceName: '/dev/xvda',
volume: ec2.BlockDeviceVolume.ebs(80)
}],
userData: ec2.UserData.forLinux()
},
fileSystem: {
throughputMode: efs.ThroughputMode.ELASTIC,
readonly: false,
containerPath: '/cache',
accessPoint: {
uid: 1000,
gid: 1000,
permission: 750
}
},
containerInsights: this.props.cloudWatchInsights
});
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = cluster.taskRole.grantPrincipal;
// Cluster permissions.
this.storage.grantWrite(cluster.taskRole);
super.bind();
} | /**
* Provider constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L168-L267 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizer.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
return (this.storage.grantRead(grantee));
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L273-L275 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizer.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'text/plain'
]);
} | /**
* @returns an array of mime-types supported as input
* type by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L281-L285 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizer.supportedOutputTypes | supportedOutputTypes(): string[] {
return ([
'audio/mpeg'
]);
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L291-L295 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizer.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.GPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L301-L305 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | BarkSynthesizer.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/bark-synthesizer/src/index.ts#L314-L319 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ElevenLabsSynthesizerBuilder.withApiKey | public withApiKey(apiKey: secrets.ISecret) {
this.middlewareProps.apiKey = apiKey;
return (this);
} | /**
* Sets the API key to use.
* @param apiKey the API key to use.
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/index.ts#L96-L99 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ElevenLabsSynthesizerBuilder.withModel | public withModel(model: ElevenLabsModel) {
this.middlewareProps.model = model;
return (this);
} | /**
* The model to use for the synthesis.
* @param model the model to use.
* @default 'eleven_multilingual_v2'
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/index.ts#L107-L110 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ElevenLabsSynthesizerBuilder.withVoice | public withVoice(voice: string, settings?: VoiceSettings) {
if (settings) {
this.middlewareProps.voiceSettings = settings;
}
this.middlewareProps.voice = voice;
return (this);
} | /**
* The voice to use for the synthesis.
* @param voice the voice to use.
* @param settings the voice settings to use.
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/index.ts#L118-L124 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ElevenLabsSynthesizerBuilder.withOutputFormat | public withOutputFormat(format: ElevenLabs.OutputFormat) {
this.middlewareProps.outputFormat = format;
return (this);
} | /**
* The output format to use for the synthesis.
* @param format the format to use.
* @default mp3_44100_128
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/index.ts#L132-L135 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ElevenLabsSynthesizerBuilder.build | public build(): ElevenLabsSynthesizer {
return (new ElevenLabsSynthesizer(
this.scope,
this.identifier, {
...this.middlewareProps as ElevenLabsSynthesizerProps,
...this.props
}
));
} | /**
* @returns a new instance of the `ElevenLabsSynthesizer`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/index.ts#L141-L149 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ElevenLabsSynthesizer.constructor | constructor(scope: Construct, id: string, private props: ElevenLabsSynthesizerProps) {
super(scope, id, description, {
...props,
queueVisibilityTimeout: cdk.Duration.seconds(
2 * PROCESSING_TIMEOUT.toSeconds()
)
});
// Validate the properties.
this.props = this.parse(ElevenLabsSynthesizerPropsSchema, props);
///////////////////////////////////////////
//////// Processing Storage ///////
///////////////////////////////////////////
this.storage = new CacheStorage(this, 'Storage', {
encryptionKey: this.props.kmsKey
});
///////////////////////////////////////////
////// Middleware Event Handler ////
///////////////////////////////////////////
this.processor = new node.NodejsFunction(this, 'Compute', {
description: 'A function converting text to speech using the Elevenlabs API.',
entry: path.resolve(__dirname, 'lambdas', 'processor', 'index.js'),
vpc: props.vpc,
memorySize: props.maxMemorySize ?? DEFAULT_MEMORY_SIZE,
timeout: PROCESSING_TIMEOUT,
runtime: EXECUTION_RUNTIME,
architecture: lambda.Architecture.ARM_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: props.kmsKey,
logGroup: this.logGroup,
reservedConcurrentExecutions: this.props.maxConcurrency ?? DEFAULT_MAX_CONCURRENCY,
insightsVersion: props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
SNS_TARGET_TOPIC: this.eventBus.topicArn,
PROCESSED_FILES_BUCKET: this.storage.id(),
ELEVENLABS_API_KEY_SECRET_NAME: props.apiKey.secretName,
ELEVENLABS_MODEL: this.props.model,
ELEVENLABS_VOICE: this.props.voice,
ELEVENLABS_VOICE_SETTINGS: this.props.voiceSettings ?
JSON.stringify(this.props.voiceSettings) :
'{}',
ELEVENLABS_OUTPUT_FORMAT: this.props.outputFormat
},
bundling: {
minify: true,
externalModules: [
'@aws-sdk/client-s3',
'@aws-sdk/client-sns'
]
}
});
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = this.processor.grantPrincipal;
// Plug the SQS queue into the lambda function.
this.processor.addEventSource(new sources.SqsEventSource(this.eventQueue, {
batchSize: this.props.batchSize ?? DEFAULT_BATCH_SIZE,
maxBatchingWindow: this.props.batchingWindow ?? DEFAULT_BATCHING_WINDOW,
maxConcurrency: this.props.maxConcurrency ?? DEFAULT_MAX_CONCURRENCY,
reportBatchItemFailures: true
}));
// Grant the compute type permissions to
// publish to the SNS topic.
this.eventBus.grantPublish(this.grantPrincipal);
// Grant the lambda function permissions to
// write to the storage.
this.storage.grantWrite(this.processor);
// Grant the lambda function permissions to
// read from the API key secret.
props.apiKey.grantRead(this.processor);
super.bind();
} | /**
* Construct constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/index.ts#L176-L262 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ElevenLabsSynthesizer.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
return (this.storage.grantRead(grantee));
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/index.ts#L268-L270 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ElevenLabsSynthesizer.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'text/plain'
]);
} | /**
* @returns an array of mime-types supported as input
* type by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/index.ts#L276-L280 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ElevenLabsSynthesizer.supportedOutputTypes | supportedOutputTypes(): string[] {
return ([
'audio/mpeg'
]);
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/index.ts#L286-L290 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ElevenLabsSynthesizer.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/index.ts#L296-L300 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | ElevenLabsSynthesizer.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/index.ts#L309-L314 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettingsBuilder.withStability | public withStability(stability: number) {
this.props.stability = stability;
return (this);
} | /**
* Sets the stability slider.
* @see https://elevenlabs.io/docs/speech-synthesis/voice-settings
* @param stability the stability slider.
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L82-L85 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettingsBuilder.withSimilarityBoost | public withSimilarityBoost(similarity: number) {
this.props.similarity_boost = similarity;
return (this);
} | /**
* Sets the similarity slider.
* @see https://elevenlabs.io/docs/speech-synthesis/voice-settings
* @param similarity the similarity slider.
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L93-L96 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettingsBuilder.withStyle | public withStyle(style: number) {
this.props.style = style;
return (this);
} | /**
* Sets the style slider.
* @see https://elevenlabs.io/docs/speech-synthesis/voice-settings
* @param style the style slider.
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L104-L107 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettingsBuilder.withSpeakerBoost | public withSpeakerBoost(useSpeakerBoost: boolean) {
this.props.use_speaker_boost = useSpeakerBoost;
return (this);
} | /**
* Sets whether to enable speaker boost.
* @see https://elevenlabs.io/docs/speech-synthesis/voice-settings
* @param useSpeakerBoost whether to enable speaker boost.
* @returns the builder instance.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L115-L118 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettingsBuilder.build | public build(): VoiceSettings {
return (VoiceSettings.from(this.props));
} | /**
* @returns a new instance of the `VoiceSettings`
* constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L124-L126 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettings.constructor | constructor(public props: VoiceSettingsProps) {} | /**
* Creates a new instance of the `VoiceSettings` class.
* @param props the task properties.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L143-L143 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettings.getStability | public getStability() {
return (this.props.stability);
} | /**
* @returns the stability slider.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L148-L150 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettings.getSimilarityBoost | public getSimilarityBoost() {
return (this.props.similarity_boost);
} | /**
* @returns the similarity slider.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L155-L157 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettings.getStyle | public getStyle() {
return (this.props.style);
} | /**
* @returns the style slider.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L162-L164 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettings.getSpeakerBoost | public getSpeakerBoost() {
return (this.props.use_speaker_boost);
} | /**
* @returns whether to enable speaker boost.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L169-L171 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettings.from | public static from(props: any) {
return (new VoiceSettings(VoiceSettingsPropsSchema.parse(props)));
} | /**
* Creates a new instance of the `VoiceSettings` class.
* @param props the task properties.
* @returns a new instance of the `VoiceSettings` class.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L178-L180 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | VoiceSettings.toJSON | public toJSON() {
return (this.props);
} | /**
* @returns the JSON representation of the task.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/definitions/voice-settings.ts#L185-L187 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | streamToBuffer | const streamToBuffer = async (readable: NodeJS.ReadableStream): Promise<Buffer> => {
const chunks: Buffer[] = [];
for await (const chunk of readable) {
chunks.push(chunk as Buffer);
}
return (Buffer.concat(chunks));
} | /**
* Convert a readable stream to a buffer.
* @param readable the readable stream to convert.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/lambdas/processor/index.ts#L95-L101 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.getOutputType | private getOutputType(): { mimeType: string, extension: string } {
if (ELEVENLABS_OUTPUT_FORMAT.startsWith('mp3')) {
return ({ mimeType: 'audio/mpeg', extension: 'mp3' });
} else if (ELEVENLABS_OUTPUT_FORMAT.startsWith('pcm')) {
return ({ mimeType: 'audio/L16', extension: 'pcm' });
} else if (ELEVENLABS_OUTPUT_FORMAT.startsWith('ulaw')) {
return ({ mimeType: 'audio/basic', extension: 'ulaw' });
} else {
throw new Error(`Unsupported output format: ${ELEVENLABS_OUTPUT_FORMAT}`);
}
} | /**
* @returns the output type based on the output format.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/lambdas/processor/index.ts | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.handler | async handler(event: SQSEvent, _: Context): Promise<SQSBatchResponse> {
return (await processPartialResponse(
event,
(record: SQSRecord) => this.processEvent(
CloudEvent.from(JSON.parse(record.body))
),
processor
));
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/elevenlabs-synthesizer/src/lambdas/processor/index.ts#L163-L171 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizerBuilder.constructor | constructor() {
super();
this.providerProps.voiceMapping = {};
} | /**
* Builder constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L79-L82 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizerBuilder.withLanguageOverride | public withLanguageOverride(language: PollyLanguage) {
this.providerProps.languageOverride = language;
return (this);
} | /**
* Specifies the language to assume the source
* document being written in.
* @see https://docs.aws.amazon.com/polly/latest/dg/SupportedLanguage.html
* @param language the language to assume.
* @returns the builder itself.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L91-L94 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizerBuilder.withVoiceMapping | public withVoiceMapping(language: PollyLanguage, ...voiceArray: VoiceDescriptor[]) {
const languageVoices = this.providerProps.voiceMapping![language];
// Verify that the voices match the given language.
const incompatibleVoices = voiceArray.filter(voice =>
!map
.filter(voice => voice['ISO-639-1'] === language)
.find(v => v.Id === voice.voice)
);
// Throw an error if there are incompatible voices.
if (incompatibleVoices.length > 0) {
throw new Error(
`The following voices are not available for the language ${language}: ` +
`${incompatibleVoices.map(v => v.voice).join(', ')}`
);
}
if (languageVoices) {
this.providerProps.voiceMapping![language] = [
...languageVoices,
...voiceArray
];
return (this);
}
this.providerProps.voiceMapping![language] = voiceArray;
return (this);
} | /**
* Specifies a mapping between a language and a voice descriptor.
* @param language the language to map.
* @param voice the voice descriptor to map.
* @see https://docs.aws.amazon.com/polly/latest/dg/voicelist.html
* @returns the builder itself.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L103-L130 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizerBuilder.build | public build(): PollySynthesizer {
return (new PollySynthesizer(
this.scope,
this.identifier, {
...this.providerProps as PollySynthesizerProps,
...this.props
}
));
} | /**
* @returns a new instance of the `PollySynthesizer`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L136-L144 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizer.constructor | constructor(scope: Construct, id: string, private props: PollySynthesizerProps) {
super(scope, id, description, {
...props,
queueVisibilityTimeout: cdk.Duration.seconds(
6 * PROCESSING_TIMEOUT.toSeconds()
)
});
// Validating the properties.
this.props = this.parse(PollySynthesizerSchema, props);
///////////////////////////////////////////
//////// Processing Storage ///////
///////////////////////////////////////////
this.storage = new CacheStorage(this, 'Storage', {
encryptionKey: this.props.kmsKey
});
///////////////////////////////////////////
//////// Processing Database //////
///////////////////////////////////////////
// The table holding mappings between synthesis jobs
// and document event metadata.
this.table = new dynamodb.Table(this, 'Table', {
partitionKey: {
name: 'SynthesisTaskId',
type: dynamodb.AttributeType.STRING
},
timeToLiveAttribute: 'ttl',
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
removalPolicy: cdk.RemovalPolicy.DESTROY,
stream: dynamodb.StreamViewType.NEW_IMAGE,
encryptionKey: props.kmsKey
});
///////////////////////////////////////////
/////// Notification Topic ///////
///////////////////////////////////////////
// The SNS topic to which Amazon Polly will publish
// synthesis results.
this.resultTopic = new sns.Topic(this, 'EventBus', {
masterKey: props.kmsKey
});
///////////////////////////////////////////
////// Event Handler Function //////
///////////////////////////////////////////
// The event handler handles input events.
this.eventHandler = this.createEventHandler('EventHandler');
// Plug the SQS queue into the event processor.
this.eventHandler.addEventSource(new sources.SqsEventSource(this.eventQueue, {
batchSize: 1,
maxConcurrency: DEFAULT_MAX_CONCURRENCY,
reportBatchItemFailures: true
}));
// Allow the event handler to invoke Amazon Polly.
this.eventHandler.addToRolePolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
'polly:StartSpeechSynthesisTask',
'polly:GetSpeechSynthesisTask',
'polly:ListSpeechSynthesisTasks'
],
resources: ['*']
}));
// Allow the event handler write access to the storage.
this.storage.grantWrite(this.eventHandler);
// Allow the event handler to publish to the event bus.
this.resultTopic.grantPublish(this.eventHandler);
// Allow the event handler to write to the table.
this.table.grantWriteData(this.eventHandler);
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant the processing
// lambda permissions to access their resources.
this.grantPrincipal = this.eventHandler.grantPrincipal;
///////////////////////////////////////////
////// Result Handler Function /////
///////////////////////////////////////////
// The result handler processes results from
// Amazon Polly.
this.resultHandler = this.createResultHandler('ResultHandler');
// Invoke the result handler upon a new SNS message.
this.resultHandler.addEventSource(new sources.SnsEventSource(this.resultTopic));
// Function permissions.
this.eventBus.grantPublish(this.resultHandler);
this.table.grantReadData(this.resultHandler);
this.storage.grantRead(this.resultHandler);
// If a KMS key is provided, grant the function
// permissions to decrypt the documents.
if (this.props.kmsKey) {
this.props.kmsKey.grantEncryptDecrypt(this.resultHandler);
}
super.bind();
} | /**
* Provider constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L188-L297 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizer.createEventHandler | private createEventHandler(id: string): lambda.IFunction {
return (new node.NodejsFunction(this, id, {
description: 'A function creating synthesis tasks on Amazon Polly.',
entry: path.resolve(__dirname, 'lambdas', 'event-handler', 'index.js'),
vpc: this.props.vpc,
timeout: PROCESSING_TIMEOUT,
runtime: EXECUTION_RUNTIME,
architecture: lambda.Architecture.ARM_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
insightsVersion: this.props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
PROCESSED_FILES_BUCKET: this.storage.id(),
LANGUAGE_OVERRIDE: this.props.languageOverride ?? '',
SNS_RESULT_TOPIC: this.resultTopic.topicArn,
MAPPING_TABLE: this.table.tableName,
VOICE_MAPPING: JSON.stringify(this.props.voiceMapping)
},
bundling: {
minify: true,
externalModules: [
'@aws-sdk/client-s3',
'@aws-sdk/client-polly'
]
}
}));
} | /**
* Creates the event handler lambda function.
* @param id the identifier of the lambda function.
* @returns the lambda function.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L304-L335 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizer.createResultHandler | private createResultHandler(id: string): lambda.IFunction {
return (new node.NodejsFunction(this, id, {
description: 'A function handling results from Amazon Polly.',
entry: path.resolve(__dirname, 'lambdas', 'result-handler', 'index.js'),
vpc: this.props.vpc,
timeout: PROCESSING_TIMEOUT,
runtime: EXECUTION_RUNTIME,
architecture: lambda.Architecture.ARM_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
insightsVersion: this.props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
SNS_TARGET_TOPIC: this.eventBus.topicArn,
MAPPING_TABLE: this.table.tableName
},
bundling: {
minify: true,
externalModules: [
'@aws-sdk/client-s3',
'@aws-sdk/client-sns',
'@aws-sdk/client-polly'
]
}
}));
} | /**
* Creates the result handler lambda function.
* @param id the identifier of the lambda function.
* @returns the lambda function.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L342-L371 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizer.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
return (this.storage.grantRead(grantee));
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L377-L379 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizer.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'text/plain'
]);
} | /**
* @returns an array of mime-types supported as input
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L385-L389 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizer.supportedOutputTypes | supportedOutputTypes(): string[] {
return ([
'audio/mpeg'
]);
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L395-L399 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizer.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L405-L409 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | PollySynthesizer.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/index.ts#L418-L423 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | groupBy | const groupBy = <T, K extends keyof any>(arr: T[], key: (i: T) => K) =>
arr.reduce((groups, item) => {
(groups[key(item)] ||= []).push(item);
return groups;
}, {} as Record<K, T[]>
); | /**
* Group an array of elements by a given key.
* @param arr the array to group.
* @param key the key to group by.
* @returns a record mapping the given key to the
* elements of the array.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/lambdas/event-handler/get-descriptor.ts#L46-L51 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getTtl | const getTtl = () => {
const SECONDS_IN_AN_HOUR = 60 * 60;
return (Math.round(Date.now() / 1000) + (24 * SECONDS_IN_AN_HOUR));
}; | /**
* This method computes the time-to-live value for events stored in DynamoDB.
* The purpose is to ensure that elements within the table are automatically
* deleted after a certain amount of time.
* @returns a time-to-live value for events stored in DynamoDB.
* @default 24 hours.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/lambdas/event-handler/index.ts#L72-L75 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.processEvent | async processEvent(event: CloudEvent): Promise<any> {
const document = event.data().document();
const ttl = getTtl();
// Load the input document in memory.
const text = await document.data().asBuffer();
// Resolve the language, voice and engine to use.
const descriptor = getDescriptor(event);
// Schedule a new synthesis task.
const res = await polly.send(new StartSpeechSynthesisTaskCommand({
OutputFormat: 'mp3',
Text: text.toString(),
Engine: descriptor.engine,
VoiceId: descriptor.voice,
OutputS3BucketName: TARGET_BUCKET,
SnsTopicArn: RESULT_TOPIC
}));
// Create a new entry in DynamoDB.
return (await dynamodb.send(new PutItemCommand({
TableName: process.env.MAPPING_TABLE,
Item: {
// The synthesis task identifier.
SynthesisTaskId: { S: res.SynthesisTask?.TaskId as string },
// The document event is serialized in the table as well, to
// keep an association between the document and the synthesis.
event: { S: JSON.stringify(event) },
// Every entry in the table has a time-to-live value that
// is used to automatically delete entries after a certain
// amount of time.
ttl: { N: ttl.toString() }
}
})));
} | /**
* @param event the event to process.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/lambdas/event-handler/index.ts#L88-L123 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.handler | async handler(event: SQSEvent, _: Context): Promise<SQSBatchResponse> {
return (await processPartialResponse(
event,
(record: SQSRecord) => this.processEvent(
CloudEvent.from(JSON.parse(record.body))
),
processor
));
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/lambdas/event-handler/index.ts#L132-L140 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.getJobEvent | private async getJobEvent(taskId: string): Promise<CloudEvent> {
const { Item } = await dynamodb.send(new GetItemCommand({
TableName: process.env.MAPPING_TABLE,
Key: {
SynthesisTaskId: { S: taskId }
}
}));
return (CloudEvent.from(JSON.parse(Item?.event.S as string)));
} | /**
* @param taskId the Amazon Polly task identifier
* associated with the cloud event to retrieve.
* @returns the cloud event associated with the given
* Amazon Polly task identifier.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/lambdas/result-handler/index.ts#L61-L69 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.getObject | private async getObject(bucket: string, key: string): Promise<HeadObjectCommandOutput> {
const res = await s3.send(new HeadObjectCommand({
Bucket: bucket,
Key: key
}));
return (res);
} | /**
* Retrieves object metadata from S3.
* @param bucket the bucket name.
* @param key the object key.
* @returns the object metadata.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/lambdas/result-handler/index.ts#L77-L83 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.handler | async handler(event: SNSEvent, _: Context): Promise<any> {
for (const record of event.Records) {
try {
await this.processEvent(JSON.parse(record.Sns.Message));
} catch (err) {
logger.error(err as any);
throw err;
}
}
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/polly-synthesizer/src/lambdas/result-handler/index.ts#L115-L124 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | TranscribeAudioProcessorBuilder.withOutputFormats | public withOutputFormats(...formats: OutputFormat[]) {
this.providerProps.outputFormats = formats;
return (this);
} | /**
* Sets the output format to use.
* @param formats the output formats to use as
* an output of the transcription.
* @default ['vtt']
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/index.ts#L73-L76 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | TranscribeAudioProcessorBuilder.build | public build(): TranscribeAudioProcessor {
return (new TranscribeAudioProcessor(
this.scope,
this.identifier, {
...this.providerProps as TranscribeAudioProcessorProps,
...this.props
}
));
} | /**
* @returns a new instance of the `TranscribeAudioProcessor`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/index.ts#L82-L90 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | TranscribeAudioProcessor.constructor | constructor(scope: Construct, id: string, private props: TranscribeAudioProcessorProps) {
super(scope, id, description, props);
// Validate the properties.
this.props = this.parse(TranscribeAudioProcessorSchema, props);
///////////////////////////////////////////
///////// Processing Storage //////
///////////////////////////////////////////
this.storage = new CacheStorage(this, 'Storage', {
encryptionKey: this.props.kmsKey
});
///////////////////////////////////////////
//////// Processing Database //////
///////////////////////////////////////////
// The table holding mappings between transcription jobs
// and document event metadata.
this.table = new dynamodb.Table(this, 'Table', {
partitionKey: {
name: 'TranscriptionJobId',
type: dynamodb.AttributeType.STRING
},
timeToLiveAttribute: 'ttl',
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
removalPolicy: cdk.RemovalPolicy.DESTROY,
encryptionKey: this.props.kmsKey
});
///////////////////////////////////////////
////// Amazon Transcribe Role /////
///////////////////////////////////////////
// The role allowing Amazon Transcribe to access
// the audio files.
this.transcribeRole = new iam.Role(this, 'TranscribeRole', {
assumedBy: new iam.ServicePrincipal('transcribe.amazonaws.com')
});
// Allow the Amazon Transcribe service to write
// transcription results to the bucket.
this.storage.grantWrite(this.transcribeRole);
///////////////////////////////////////////
///// Input Handler Function ///////
///////////////////////////////////////////
// Handles events from the middleware's input queue and
// writes them to the DynamoDB table.
const inputHandler = this.createInputHandler('InputHandler');
// Function permissions.
this.table.grantWriteData(inputHandler);
this.eventQueue.grantConsumeMessages(inputHandler);
this.transcribeRole.grantPassRole(inputHandler.grantPrincipal);
this.storage.grantWrite(inputHandler);
// Allow the function to create transcription jobs.
inputHandler.addToRolePolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
'transcribe:StartTranscriptionJob'
],
resources: ['*']
}));
// Plug the middleware's input SQS queue into the
// input handler function.
inputHandler.addEventSource(new sources.SqsEventSource(this.eventQueue, {
batchSize: this.props.batchSize ?? 1,
maxConcurrency: 5,
reportBatchItemFailures: true
}));
// Allows this construct to act as a `IGrantable`
// for other middlewares to grant Amazon Transcribe
// the permissions to access their resources.
this.grantPrincipal = inputHandler.grantPrincipal;
///////////////////////////////////////////
////// Result Handler Function /////
///////////////////////////////////////////
// Handles transcription results and forwards them
// to the SNS topic.
const resultHandler = this.createResultHandler('ResultHandler');
// Listen for new transcription results on the bucket.
for (const format of this.props.outputFormats) {
resultHandler.addEventSource(new sources.S3EventSource(
this.storage.getBucket() as s3.Bucket, {
events: [
s3.EventType.OBJECT_CREATED
],
filters: [{
prefix: 'transcriptions/',
suffix: `.${format}`
}]
}));
}
// Function permissions.
this.eventBus.grantPublish(resultHandler);
this.table.grantReadData(resultHandler);
// If a KMS key is provided, grant the function
// permissions to decrypt the documents.
if (this.props.kmsKey) {
this.props.kmsKey.grantEncryptDecrypt(resultHandler);
}
super.bind();
} | /**
* Provider constructor.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/index.ts#L124-L238 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | TranscribeAudioProcessor.onSourceAdded | protected onSourceAdded(source: Middleware): void {
super.onSourceAdded(source);
source.grantReadProcessedDocuments(this.transcribeRole);
} | /**
* Called back when a new source middleware is connected
* to this middleware. The purpose of overriding this method
* is to allow the Amazon Transcribe role to access the source's
* processed documents.
* @param source the source middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/index.ts#L247-L250 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | TranscribeAudioProcessor.createInputHandler | private createInputHandler(id: string) {
const handlerPath = path.resolve(__dirname, 'lambdas', 'input-handler');
// Compiling the properties into options that the Amazon Transcribe
// API understands.
const transcribeOptions = compile(
this.props,
this.storage.id(),
this.transcribeRole
);
return (new node.NodejsFunction(this, id, {
description: 'Inserts new transcription jobs in DynamoDB.',
entry: path.resolve(handlerPath, 'index.js'),
vpc: this.props.vpc,
runtime: EXECUTION_RUNTIME,
architecture: lambda.Architecture.ARM_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
insightsVersion: this.props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
reservedConcurrentExecutions: 5,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
MAPPING_TABLE: this.table.tableName,
TRANSCRIBE_OPTS: JSON.stringify(transcribeOptions)
},
bundling: {
minify: true,
externalModules: [
'@aws-sdk/client-dynamodb',
'@aws-sdk/client-transcribe'
]
}
}));
} | /**
* Creates a new input handler function which handles
* events from the middleware's input queue and writes
* them to the DynamoDB table for further processing.
* @param id the construct identifier.
* @returns the input handler function.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/index.ts#L259-L297 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | TranscribeAudioProcessor.createResultHandler | private createResultHandler(id: string) {
const handlerPath = path.resolve(__dirname, 'lambdas', 'result-handler');
return (new node.NodejsFunction(this, id, {
description: 'Listens for transcription results and forwards them to the SNS topic.',
entry: path.resolve(handlerPath, 'index.js'),
vpc: this.props.vpc,
runtime: EXECUTION_RUNTIME,
architecture: lambda.Architecture.ARM_64,
tracing: lambda.Tracing.ACTIVE,
environmentEncryption: this.props.kmsKey,
logGroup: this.logGroup,
insightsVersion: this.props.cloudWatchInsights ?
LAMBDA_INSIGHTS_VERSION :
undefined,
environment: {
POWERTOOLS_SERVICE_NAME: description.name,
POWERTOOLS_METRICS_NAMESPACE: NAMESPACE,
MAPPING_TABLE: this.table.tableName,
SNS_TARGET_TOPIC: this.eventBus.topicArn
},
bundling: {
minify: true,
externalModules: [
'@aws-sdk/client-sns',
'@aws-sdk/client-dynamodb'
]
}
}));
} | /**
* @param id the construct identifier.
* @returns the result handler function which handles
* transcription results and forwards them to the SNS topic.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/index.ts#L304-L333 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | TranscribeAudioProcessor.grantReadProcessedDocuments | grantReadProcessedDocuments(grantee: iam.IGrantable): iam.Grant {
return (this.storage.grantRead(grantee));
} | /**
* Allows a grantee to read from the processed documents
* generated by this middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/index.ts#L339-L341 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | TranscribeAudioProcessor.supportedInputTypes | supportedInputTypes(): string[] {
return ([
'audio/mpeg',
'audio/mp4',
'audio/x-m4a',
'audio/wav',
'audio/webm',
'audio/flac',
'audio/x-flac',
'audio/ogg',
'audio/x-ogg',
'audio/amr'
]);
} | /**
* @returns an array of mime-types supported as input
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/index.ts#L347-L360 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | TranscribeAudioProcessor.supportedOutputTypes | supportedOutputTypes(): string[] {
return ([
'application/json',
'application/x-subrip',
'text/vtt'
]);
} | /**
* @returns an array of mime-types supported as output
* type by the data producer.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/index.ts#L366-L372 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | TranscribeAudioProcessor.supportedComputeTypes | supportedComputeTypes(): ComputeType[] {
return ([
ComputeType.CPU
]);
} | /**
* @returns the supported compute types by a given
* middleware.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/index.ts#L378-L382 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | TranscribeAudioProcessor.conditional | conditional() {
return (super
.conditional()
.and(when('type').equals('document-created'))
);
} | /**
* @returns the middleware conditional statement defining
* in which conditions this middleware should be executed.
* In this case, we want the middleware to only be invoked
* when the document mime-type is supported, and the event
* type is `document-created`.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/index.ts#L391-L396 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | getTtl | const getTtl = () => {
const SECONDS_IN_AN_HOUR = 60 * 60;
return (Math.round(Date.now() / 1000) + (24 * SECONDS_IN_AN_HOUR));
}; | /**
* This method computes the time-to-live value for events stored in DynamoDB.
* The purpose is to ensure that elements within the table are automatically
* deleted after a certain amount of time.
* @returns a time-to-live value for events stored in DynamoDB.
* @default 24 hours.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/lambdas/input-handler/index.ts#L64-L67 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.processEvent | async processEvent(event: CloudEvent): Promise<any> {
const document = event.data().document();
const chainId = event.data().chainId();
const jobId = `${chainId}-${document.etag()}`;
const ttl = getTtl();
// Create the transcription job.
await transcribe.send(new StartTranscriptionJobCommand({
TranscriptionJobName: jobId,
Media: {
MediaFileUri: decodeURIComponent(
document.url().toString()
)
},
...TRANSCRIBE_OPTS
}));
// Create a new entry in DynamoDB.
return (await dynamodb.send(new PutItemCommand({
TableName: process.env.MAPPING_TABLE,
Item: {
// We compute a transcription identifier based on the
// document etag and the chain identifier. This will uniquely
// identify the transcription for this specific document.
TranscriptionJobId: { S: jobId },
// The document event is serialized in the table as well, to
// keep an association between the document and the transcription.
event: { S: JSON.stringify(event) },
// Every entry in the table has a time-to-live value that
// is used to automatically delete entries after a certain
// amount of time.
ttl: { N: ttl.toString() }
}
})));
} | /**
* This method processes the received event and stores
* it in DynamoDB for further processing.
* @param event the event to process.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/lambdas/input-handler/index.ts#L82-L116 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.handler | async handler(event: SQSEvent, _: Context): Promise<SQSBatchResponse> {
return (await processPartialResponse(
event,
(record: SQSRecord) => this.processEvent(
CloudEvent.from(JSON.parse(record.body))
),
processor
));
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/lambdas/input-handler/index.ts#L126-L134 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | unquote | const unquote = (key: string): string => {
return (decodeURIComponent(key.replace(/\+/g, " ")));
}; | /**
* When S3 emits an event, it will encode the object key
* in the event record using quote-encoding.
* This function restores the object key in its unencoded
* form and returns the event record with the unquoted object key.
* @param event the S3 event record.
* @returns the S3 event record with the unquoted object key.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/lambdas/result-handler/index.ts#L53-L55 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.getJobEvent | private async getJobEvent(jobId: string): Promise<CloudEvent> {
const { Item } = await dynamodb.send(new GetItemCommand({
TableName: process.env.MAPPING_TABLE,
Key: {
TranscriptionJobId: { S: jobId }
}
}));
return (CloudEvent.from(JSON.parse(Item?.event.S as string)));
} | /**
* @param jobId the Amazon Transcribe job identifier
* associated with the cloud event to retrieve.
* @returns the cloud event associated with the given
* Amazon Transcribe job identifier.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/lambdas/result-handler/index.ts#L71-L79 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | Lambda.handler | handler(event: S3Event, _: Context): Promise<any> {
return (Promise.all(
event.Records.map((record) => this.recordHandler(record))
));
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/transcribe-audio-processor/src/lambdas/result-handler/index.ts#L124-L128 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | WhisperTranscriberBuilder.withEngine | public withEngine(engine: WhisperEngine) {
this.whisperProps.engine = engine;
return (this);
} | /**
* Sets the Whisper engine to use.
* @param engine the Whisper engine to use.
* @default openai_whisper
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/whisper-transcriber/src/index.ts#L60-L63 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | WhisperTranscriberBuilder.withModel | public withModel(model: WhisperModel) {
this.whisperProps.model = model;
return (this);
} | /**
* Sets the Whisper model to use.
* @param model the Whisper model to use.
* @default small
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/whisper-transcriber/src/index.ts#L70-L73 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | WhisperTranscriberBuilder.withOutputFormat | public withOutputFormat(format: OutputFormat) {
this.whisperProps.outputFormat = format;
return (this);
} | /**
* Sets the output format to use.
* @param format the output format to use.
* @default vtt
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/whisper-transcriber/src/index.ts#L80-L83 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | WhisperTranscriberBuilder.withMaxInstances | public withMaxInstances(maxInstances: number) {
this.whisperProps.maxInstances = maxInstances;
return (this);
} | /**
* The maximum amount of instances the
* cluster can have. Keep this number to
* a reasonable value to avoid over-provisioning
* the cluster.
* @param maxInstances the maximum amount of instances.
* @default 5
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/whisper-transcriber/src/index.ts#L93-L96 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
project-lakechain | github_2023 | awslabs | typescript | WhisperTranscriberBuilder.build | public build(): WhisperTranscriber {
return (new WhisperTranscriber(
this.scope,
this.identifier, {
...this.whisperProps as WhisperTranscriberProps,
...this.props
}
));
} | /**
* @returns a new instance of the `WhisperTranscriber`
* service constructed with the given parameters.
*/ | https://github.com/awslabs/project-lakechain/blob/4285173e80584eedfc1a8424d3d1b6c1a7038088/packages/middlewares/audio-processors/whisper-transcriber/src/index.ts#L102-L110 | 4285173e80584eedfc1a8424d3d1b6c1a7038088 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.