sudhir tataraju
sudhir tataraju

Reputation: 1389

How to decode AWS Kinesis Video Stream GetMedia API output to mp3/wav?

I ingested data to (Kinesis Video Stream) KVS via AWS Connect service now using GetMedia API am able to extract the Payload but how can I convert this output to a mp3/wav ? I want to ingest this output to AWS Transcribe service to get text format of audio call ingested by AWS Connect service to KVS.

Output of Payload for below code is like :

00#AWS_KINESISVIDEO_CONTINUATION_TOKEND\x87....\x1faudio/L16;rate=8000;channels=1;\x12T\xc......00"AWS_KINESISVIDEO_MILLIS_BEHIND_NOWD\x87\x10\x00\x00\x074564302g\xc8\x10\x00\x00^E\xa3\x10\x00\x00#AWS_KINESISVIDEO_CONTINUATION_TOKEND\x87\x10\x00\x00/91343852333181432506572546233025969374566791063'

Note: Above response was too long, so pasted some of it.

import json
import boto3

kinesis_client = boto3.client('kinesisvideo', region_name='us-east-1')

response = kinesis_client.get_data_endpoint(
    StreamARN='arn:aws:kinesisvideo:us-east-1:47...,
    APIName='GET_MEDIA')

t = response['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:47...',
    StartSelector={'StartSelectorType': 'EARLIEST'})

streamingBody = stream['Payload']
print(streamingBody.read())

Please suggest how can I convert payload output to mp3/wav etc.

Upvotes: 6

Views: 3231

Answers (1)

marxan
marxan

Reputation: 15

I am facing the same problem, I can export the payload to S3 as a raw file but when I listen it, it is not properly audible like it was a crypted conversation.

I just save the payload into a file.

f = open("myAudio.wav", 'w+b')
f.write(stream['Payload'].read())
f.close() 

Upvotes: 0

Related Questions