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 (https://github.com/aws-samples/amazon-connect-realtime-transcription).
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
bucket='kinesis-video-streams-random'
key = 'streams/latest.raw'
def lambda_handler(event, context):
try:
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