package com.amazonaws.kvstranscribestreaming; import com.amazonaws.services.dynamodbv2.document.DynamoDB; import com.amazonaws.services.dynamodbv2.document.Item; import org.apache.commons.lang3.Validate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import software.amazon.awssdk.services.transcribestreaming.model.Result; import software.amazon.awssdk.services.transcribestreaming.model.TranscriptEvent; import java.text.NumberFormat; import java.time.Instant; import java.util.List; /** * TranscribedSegmentWriter writes the transcript segments to DynamoDB * *
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so. *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public class TranscribedSegmentWriter {
private String contactId;
private DynamoDB ddbClient;
private Boolean consoleLogTranscriptFlag;
private static final boolean SAVE_PARTIAL_TRANSCRIPTS = Boolean.parseBoolean(System.getenv("SAVE_PARTIAL_TRANSCRIPTS"));
private static final Logger logger = LoggerFactory.getLogger(TranscribedSegmentWriter.class);
public TranscribedSegmentWriter(String contactId, DynamoDB ddbClient, Boolean consoleLogTranscriptFlag) {
this.contactId = Validate.notNull(contactId);
this.ddbClient = Validate.notNull(ddbClient);
this.consoleLogTranscriptFlag = Validate.notNull(consoleLogTranscriptFlag);
}
public String getContactId() {
return this.contactId;
}
public DynamoDB getDdbClient() {
return this.ddbClient;
}
public void writeToDynamoDB(TranscriptEvent transcriptEvent, String tableName) {
logger.info("table name: " + tableName);
logger.info("Transcription event: " + transcriptEvent.transcript().toString());
List