in sam-app/lambda_functions/sfComprehendUtil.py [0:0]
def processTranscript(iItems):
transcripts = []
for iTranscript in iItems:
transcript = {}
if 'start_time' not in iTranscript:
if iTranscript['type'] == 'punctuation':
if len(transcripts) > 0:
lastItem = transcripts[len(transcripts)-1]
lastChar = lastItem['content'][len(lastItem['content'])-1]
if(lastChar != '.' and lastChar != ',' and lastChar != '?' and lastChar != ':' and lastChar != '!'):
lastItem['content'] += iTranscript['alternatives'][0]['content']
continue
continue
transcript['start_time'] = float(iTranscript['start_time'])
transcript['end_time'] = float(iTranscript['end_time'])
maxAlternativeConfidenceScore = 0.0
selectedAlternative = ''
for alternative in iTranscript['alternatives']:
if(float(alternative['confidence']) > maxAlternativeConfidenceScore):
selectedAlternative = alternative['content']
transcript['content'] = selectedAlternative
if(len(transcripts)>0):
lastItem = transcripts[len(transcripts)-1]
lastChar = lastItem['content'][len(lastItem['content'])-1]
if (float(transcript['start_time']) - float(lastItem['start_time']) <= 2.0) and (lastChar != '.' and lastChar != ',' and lastChar != '?' and lastChar != ':' and lastChar != '!'):
lastItem['content'] += ' '+ selectedAlternative
else:
transcripts.append(transcript)
else:
transcripts.append(transcript)
return transcripts