func()

in lambda/go/start-transcription/main.go [31:90]


func (h *Handler) Handle(ctx context.Context, input workshop.TranscribeStateMachineInput) (
	workshop.TranscribeStateMachineOutput, error,
) {
	log.Println("staring transcription,", input)
	episode := input.Episode

	mediaFormat, err := contentTypeToMediaFormat(episode.MediaContentType)
	if err != nil {
		return workshop.TranscribeStateMachineOutput{}, err
	}

	mediaURI, err := h.getS3Endpoint(episode.MediaKey)
	if err != nil {
		return workshop.TranscribeStateMachineOutput{}, err
	}

	episode.TranscribeMetadataKey = workshop.MakeEpisodeTranscribeMetadataPath(
		h.mediaKeyPrefix, episode.ID,
	)

	if episode.TranscribeJobID != "" {
		log.Println("transcription already started,", episode.TranscribeJobID)
		return workshop.TranscribeStateMachineOutput{Episode: episode}, nil
	}

	episode.TranscribeJobID, err = h.uuidProvider.GetUUID()
	if err != nil {
		return workshop.TranscribeStateMachineOutput{}, err
	}
	resp, err := h.trClient.StartTranscriptionJob(ctx,
		&tr.StartTranscriptionJobInput{
			TranscriptionJobName: &episode.TranscribeJobID,
			IdentifyLanguage:     aws.Bool(true),
			MediaFormat:          mediaFormat,
			Media: &trtypes.Media{
				MediaFileUri: &mediaURI,
			},
			Settings: &trtypes.Settings{
				MaxSpeakerLabels:  aws.Int32(10),
				ShowSpeakerLabels: aws.Bool(true),
			},
			JobExecutionSettings: &trtypes.JobExecutionSettings{
				AllowDeferredExecution: aws.Bool(true),
				DataAccessRoleArn:      &h.bucketAccessRole,
			},
			OutputBucketName: &h.bucketName,
			OutputKey:        &episode.TranscribeMetadataKey,
		},
	)
	if err != nil {
		return workshop.TranscribeStateMachineOutput{},
			fmt.Errorf("failed to start transcription job, %w", err)
	}

	log.Println("transcription started,", episode.TranscribeJobID, resp)

	return workshop.TranscribeStateMachineOutput{
		Episode: episode,
	}, nil
}