5

我正在尝试为 Amazon connect 中的呼叫中心设置语音邮件功能。我已将 Start Media 流块添加到流中。我还添加了一个由 Kinesis 流触发的 Lambda 函数。我的想法不是实时流式传输,但在流式传输完成后下载文件。

import json
import base64
import boto3
import time

def lambda_handler(event,context):
    # print(event)
    record = base64.b64decode(event["Records"][0]["kinesis"]["data"]).decode('utf-8')
    record_obj = json.loads(record)
    print('record', record)
    bucket = 'yyyy'
    key = 'streams/sample123.raw'
    # try:
    s3_client = boto3.client('s3',region_name='us-east-1')
    kinesis_client_1 = boto3.client('kinesisvideo',region_name='us-east-1')
    get_ep = kinesis_client_1.get_data_endpoint(StreamARN='arn:aws:kinesisvideo:us-east-1:237980099910:stream/xxxx/1580972532224',APIName='GET_MEDIA_FOR_FRAGMENT_LIST')
    t = get_ep['DataEndpoint']
    print(t)
    kinesis_client_2= boto3.client('kinesis-video-archived-media',region_name='us-east-1',endpoint_url=t)
    response = kinesis_client_2.list_fragments(StreamName='xxxx',
        # MaxResults=123,
        # NextToken='string',
        FragmentSelector={
            'FragmentSelectorType': 'SERVER_TIMESTAMP',
            'TimestampRange': {
                'StartTimestamp': '2020-02-07T05:21:30Z',
                'EndTimestamp': '2020-02-07T05:22:08Z'
            }
        }
        )

    fragments_list = res = [ sub['FragmentNumber'] for sub in response['Fragments'] ]
    print(fragments_list)

    stream = kinesis_client_2.get_media_for_fragment_list(
        StreamName='xxxx',
        Fragments=[
            'above list'
        ]
        )
    print(stream)
    stream_payload =stream['Payload'].read()
    s3_client.put_object(Bucket=bucket, Key=key, Body= stream_payload)

在 lambda 函数中,我尝试获取音频文件并在 s3 存储桶中下载为 .raw。当我下载并导入 audacity 工具(16 位签名 PCM,8000 Hz,1 通道)时,音频有很多噪音。有人可以告诉我如何解决这个问题吗?我想听到清晰的音频并将其转换为 .wav 文件。在 python 或 node.js 中编码。

来自 Kinesis 的 Lambda 触发器:

{
    "AWSAccountId": "xxxx",
    "AWSContactTraceRecordFormatVersion": "2017-03-10",
    "Agent": null,
    "AgentConnectionAttempts": 0,
    "Attributes": {},
    "Channel": "VOICE",
    "ConnectedToSystemTimestamp": "2020-02-07T05:21:16Z",
    "ContactId": "7f8a125c-88d6-44e7-acde-xxxx",
    "CustomerEndpoint": {
        "Address": "+",
        "Type": "TELEPHONE_NUMBER"
    },
    "DisconnectTimestamp": "2020-02-07T05:22:08Z",
    "InitialContactId": null,
    "InitiationMethod": "INBOUND",
    "InitiationTimestamp": "2020-02-07T05:21:16Z",
    "InstanceARN": "arn",
    "LastUpdateTimestamp": "2020-02-07T05:23:15Z",
    "MediaStreams": [{
        "Type": "AUDIO"
    }],
    "NextContactId": null,
    "PreviousContactId": null,
    "Queue": {
        "ARN": "arn",
        "DequeueTimestamp": "2020-02-07T05:22:08Z",
        "Duration": 44,
        "EnqueueTimestamp": "2020-02-07T05:21:24Z",
        "Name": "General Queue"
    },
    "Recording": null,
    "Recordings": [{
        "DeletionReason": null,
        "FragmentStartNumber": "91343852333181432392682062626319863574829261800",
        "FragmentStopNumber": "91343852333181432759112314254792434826550738671",
        "Location": "arn:aws:kinesisvideo:us-east-1:237980099910:stream/xxxx/1580972532224",
        "MediaStreamType": "AUDIO",
        "ParticipantType": "CUSTOMER",
        "StartTimestamp": "2020-02-07T05:21:30Z",
        "Status": null,
        "StopTimestamp": "2020-02-07T05:22:08Z",
        "StorageType": "KINESIS_VIDEO_STREAM"
    }],
    "SystemEndpoint": {
        "Address": "+",
        "Type": "TELEPHONE_NUMBER"
    },
    "TransferCompletedTimestamp": null,
    "TransferredToEndpoint": null
} 

4

0 回答 0