"""Lambda match-audio-fingerprint function module.""" import base64 from operator import itemgetter from acrcloud import acrcloud_extr_tool import boto3 import sentry_sdk from sentry_sdk.integrations.aws_lambda import AwsLambdaIntegration from src import config from src.config import app_logger if config.SENTRY_DSN: sentry_sdk.init( dsn=config.SENTRY_DSN, environment=config.ENVIRONMENT, integrations=[AwsLambdaIntegration(timeout_warning=True)] ) s3_client = boto3.client('s3') def handler(event, context): """Lambda Entry point.""" app_logger.info(event) s3_bucket, s3_key = itemgetter('bucket', 'filename')(event) file_name = '/tmp/audio.flac' s3_client.download_file(s3_bucket, s3_key, file_name) start_time_seconds = 0 audio_len_seconds = 30 is_db_fingerprint = False filter_e = 0 audio_fingerprint = acrcloud_extr_tool.create_fingerprint_by_file( file_name, start_time_seconds, audio_len_seconds, is_db_fingerprint, filter_e ) return { 'audio_fingerprint': base64.b64encode(audio_fingerprint).decode('ascii') }