Trying to configure Amazon Connect to live stream conversation to AWS Kinesis Video Streams and then triggering Lambda function (Python) that uses GetMedia API to sample this recording and send it to certain S3 bucket.

Pretty much stuck at this conversion of raw stream to .wav -> is it even possible to achieve with python? Found similar implementation but always stumble across Java (

I just need to convert this stream to .wav format for example in order for it to be playable later by common audio players and used as a Voice Mail and in similar use-cases.

import json
import boto3
import time

key = 'streams/latest.raw'

def lambda_handler(event, context):
        s3_client = boto3.client('s3',region_name='us-east-1')
        kinesis_client = boto3.client('kinesisvideo',region_name='us-east-1')

        get_ep = kinesis_client.get_data_endpoint(StreamARN='arn:aws:kinesisvideo:us-east-1:xxxxxxxxx:stream/xxxxxxxx',APIName='GET_MEDIA')

        t = get_ep['DataEndpoint']
        video_client = boto3.client('kinesis-video-media', endpoint_url=t, region_name='us-east-1')
        stream = video_client.get_media(StreamARN='arn:aws:kinesisvideo:us-east-1:xxxxxxxxx:stream/xxxxxxxx',StartSelector={'StartSelectorType': 'EARLIEST'})

        s3_client.put_object(Bucket=bucket, Key=key, Body=stream['Payload'].read())
        print("Specific Kinesis Stream stored in the S3 bucket " + bucket)
    except Exception as e:
        return e

1 Answers

Paprikamann On

There's a python module called wave, which could be useful. You can simply open the raw file and write it with the module to a .wav file. That's also the same thing that happens in the Java Lambda.

There is also an answer by abernert with an example