private Item toDynamoDbItem()

in lca-ai-stack/source/kvs_transcribe_streaming/src/main/java/com/amazonaws/kvstranscribestreaming/TranscribedSegmentWriter.java [93:136]


    private Item toDynamoDbItem(Result result, String channel) {

        String callId = this.getCallId();
        String transactionId = this.getTransactionId();
        String streamARN = this.getStreamARN();
        Item ddbItem = null;

        NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumFractionDigits(3);
        nf.setMaximumFractionDigits(3);

        if (result.alternatives().size() > 0) {
            if (!result.alternatives().get(0).transcript().isEmpty()) {

                Instant now = Instant.now();
                ddbItem = new Item()
                        .withKeyComponent("PK", String.format("ce#%s", callId))
                        .withKeyComponent("SK", String.format("ts#%s#et#%s#c#%s", now.toString(), eventType, channel))
                        .withString("Channel", channel)
                        .withString("StreamArn", streamARN)
                        .withString("TransactionId", transactionId)
                        .withString("CallId", callId)
                        .withString("SegmentId", result.resultId())
                        .withDouble("StartTime", result.startTime())
                        .withDouble("EndTime", result.endTime())
                        .withString("Transcript", result.alternatives().get(0).transcript())
                        .withBoolean("IsPartial", result.isPartial())
                        .withString("EventType", eventType)
                        .withString("CreatedAt", now.toString())
                        .withDouble("ExpiresAfter", now.plusSeconds(EXPIRATION_IN_DAYS * 24 * 3600).toEpochMilli() / 1000);

                if (consoleLogTranscriptFlag) {
                    logger.info(String.format("Thread %s %d: [%s, %s] - %s",
                            Thread.currentThread().getName(),
                            System.currentTimeMillis(),
                            nf.format(result.startTime()),
                            nf.format(result.endTime()),
                            result.alternatives().get(0).transcript()));
                }
            }
        }

        return ddbItem;
    }