added documentation.
Made the interface AWS independent some other small fixes.
MODIFY
tika-core/src/main/java/org/apache/tika/transcribe/Transcriber.java
tika-core/src/main/java/org/apache/tika/transcribe/Transcriber.java
@@ -31,21 +31,22 @@ public interface Transcriber {
/**
* Transcribe the given audio file.
*
- * @param filePath
- * @return
- * @throws TikaException When there is an error translating.
+ * @param filePath The path of the file to be transcribed.
+ * @return key for transcription lookup
+ * @throws TikaException When there is an error transcribing.
* @throws IOException
* @since TODO
*/
+
public String startTranscribeAudio(String filePath) throws TikaException, IOException;
/**
* Transcribe the given the audio file and the source language.
*
- * @param filePath
- * @param sourceLanguage
- * @return
- * @throws TikaException When there is an error translating.
+ * @param filePath The path of the file to be transcribed.
+ * @param sourceLanguage The language code for the language used in the input media file.
+ * @return key for transcription lookup
+ * @throws TikaException When there is an error transcribing.
* @throws java.io.IOException
* @since TODO
*/
@@ -54,9 +55,9 @@ public interface Transcriber {
/**
* Transcribe the given the video file.
*
- * @param filePath
- * @return
- * @throws TikaException When there is an error translating.
+ * @param filePath The path of the file to be transcribed.
+ * @return key for transcription lookup
+ * @throws TikaException When there is an error transcribing.
* @throws java.io.IOException
* @since TODO
*/
@@ -65,10 +66,10 @@ public interface Transcriber {
/**
* Transcribe the given the video file and the source language.
*
- * @param filePath
- * @param sourceLanguage
- * @return
- * @throws TikaException When there is an error translating.
+ * @param filePath The path of the file to be transcribed.
+ * @param sourceLanguage The language code for the language used in the input media file.
+ * @return key for transcription lookup
+ * @throws TikaException When there is an error transcribing.
* @throws java.io.IOException
* @since TODO
*/
@@ -79,11 +80,4 @@ public interface Transcriber {
* @since Tika TODO
*/
public boolean isAvailable();
-
- /**
- * Returns transcription result using specific key
- * @param fileNameS3
- * @return transcribed text
- */
- public String getTranscriptResult(String fileNameS3);
}

MODIFY
tika-transcribe/src/main/java/org/apache/tika/transcribe/AmazonTranscribe.java
tika-transcribe/src/main/java/org/apache/tika/transcribe/AmazonTranscribe.java
@@ -69,8 +69,7 @@ public class AmazonTranscribe implements Transcriber {
}
private String getJobKey() {
- UUID uuid = UUID.randomUUID();
- return uuid.toString();
+ return UUID.randomUUID().toString();
}
/**
@@ -78,7 +77,9 @@ public class AmazonTranscribe implements Transcriber {
* {@link PutObjectRequest} object to upload a file to the
* specified bucket and jobName. After constructing the request,
* users may optionally specify object metadata or a canned ACL as well.
+ *
* @param filePath The path of the file to upload to Amazon S3.
+ * @param jobName The unique job name for each job(UUID).
*/
private void uploadFileToBucket(String filePath, String jobName) {
PutObjectRequest request = new PutObjectRequest(this.bucketName, jobName, new File(filePath));
@@ -87,9 +88,10 @@ public class AmazonTranscribe implements Transcriber {
/**
* Starts AWS Transcribe Job without language specification for Audio
- * @param filePath
+ *
+ * @param filePath The path of the file to upload to Amazon S3.
* @return key for transcription lookup
- * @throws TikaException
+ * @throws TikaException When there is an error transcribing.
* @throws IOException
*/
@Override
@@ -106,13 +108,16 @@ public class AmazonTranscribe implements Transcriber {
amazonTranscribe.startTranscriptionJob(startTranscriptionJobRequest);
return jobName;
}
+
/**
* Starts AWS Transcribe Job with language specification for Audio
- * @param filePath
- * @param sourceLanguage
+ *
+ * @param filePath The path of the file to upload to Amazon S3.
+ * @param sourceLanguage The language code for the language used in the input media file
* @return key for transcription lookup
- * @throws TikaException
+ * @throws TikaException When there is an error transcribing.
* @throws IOException
+ * @see <a href="https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/transcribe/model/LanguageCode.html">AWS Language Code</a>
*/
@Override
public String startTranscribeAudio(String filePath, String sourceLanguage) throws TikaException, IOException {
@@ -123,7 +128,7 @@ public class AmazonTranscribe implements Transcriber {
Media media = new Media();
media.setMediaFileUri(amazonS3.getUrl(bucketName, filePath).toString());
startTranscriptionJobRequest.withMedia(media)
- .withLanguageCode(LanguageCode.valueOf(sourceLanguage))
+ .withLanguageCode(LanguageCode.fromValue(sourceLanguage))
.withOutputBucketName(this.bucketName)
.setTranscriptionJobName(jobName);
amazonTranscribe.startTranscriptionJob(startTranscriptionJobRequest);
@@ -132,9 +137,10 @@ public class AmazonTranscribe implements Transcriber {
/**
* Starts AWS Transcribe Job without language specification for Video
- * @param filePath
+ *
+ * @param filePath The path of the file to upload to Amazon S3.
* @return key for transcription lookup
- * @throws TikaException
+ * @throws TikaException When there is an error transcribing.
* @throws IOException
*/
@Override
@@ -154,11 +160,13 @@ public class AmazonTranscribe implements Transcriber {
/**
* Starts AWS Transcribe Job with language specification for Audio
- * @param filePath
- * @param sourceLanguage
+ *
+ * @param filePath The path of the file to upload to Amazon S3.
+ * @param sourceLanguage The language code for the language used in the input media file.
* @return key for transcription lookup
- * @throws TikaException
+ * @throws TikaException When there is an error transcribing.
* @throws IOException
+ * @see <a href="https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/transcribe/model/LanguageCode.html">AWS Language Code</a>
*/
@Override
public String startTranscribeVideo(String filePath, String sourceLanguage) throws TikaException, IOException {
@@ -169,7 +177,7 @@ public class AmazonTranscribe implements Transcriber {
Media media = new Media();
media.setMediaFileUri(amazonS3.getUrl(bucketName, filePath).toString());
startTranscriptionJobRequest.withMedia(media)
- .withLanguageCode(LanguageCode.valueOf(sourceLanguage))
+ .withLanguageCode(LanguageCode.fromValue(sourceLanguage))
.withOutputBucketName(this.bucketName)
.setTranscriptionJobName(jobName);
amazonTranscribe.startTranscriptionJob(startTranscriptionJobRequest);
@@ -223,10 +231,9 @@ public class AmazonTranscribe implements Transcriber {
/**
* Gets Transcription result from AWS S3 bucket given bucketName and jobName
*
- * @param fileNameS3
- * @return
+ * @param fileNameS3 The path of the file to upload to Amazon S3.
+ * @return The transcribed result.
*/
- @Override
public String getTranscriptResult(String fileNameS3) {
TranscriptionJob transcriptionJob = retrieveObjectWhenJobCompleted(fileNameS3);
if (transcriptionJob != null && !TranscriptionJobStatus.FAILED.equals(transcriptionJob.getTranscriptionJobStatus())) {
@@ -238,8 +245,8 @@ public class AmazonTranscribe implements Transcriber {
/**
* Private helper function to get object from s3
*
- * @param jobName
- * @return
+ * @param jobName The unique job name for each job(UUID).
+ * @return TranscriptionJob object
*/
private TranscriptionJob retrieveObjectWhenJobCompleted(String jobName) {
GetTranscriptionJobRequest getTranscriptionJobRequest = new GetTranscriptionJobRequest();

added documentation.
Made the interface AWS independent some other small fixes.