From 2c5003347aa53543d3ef50351fb35032510e3501 Mon Sep 17 00:00:00 2001 From: philmcmahon Date: Fri, 30 Aug 2024 12:15:22 +0100 Subject: [PATCH 1/6] Add support for english translation of the audio --- packages/api/src/index.ts | 1 + packages/backend-common/src/sqs.ts | 11 +++-- packages/client/src/components/UploadForm.tsx | 47 +++++++++++++++++-- packages/common/src/types.ts | 3 ++ packages/output-handler/src/index.ts | 17 +++++-- packages/worker/src/index.ts | 2 + packages/worker/src/transcribe.ts | 9 +++- 7 files changed, 75 insertions(+), 15 deletions(-) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 0375d74d..78868d3a 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -125,6 +125,7 @@ const getApp = async () => { body.data.fileName, signedUrl, body.data.languageCode, + body.data.translationRequested, ); if (isSqsFailure(sendResult)) { res.status(500).send(sendResult.errorMsg); diff --git a/packages/backend-common/src/sqs.ts b/packages/backend-common/src/sqs.ts index b8ae01d1..69251180 100644 --- a/packages/backend-common/src/sqs.ts +++ b/packages/backend-common/src/sqs.ts @@ -57,7 +57,7 @@ export const isSqsFailure = ( ): result is SQSFailure => result.status === AWSStatus.Failure; export const generateOutputSignedUrlAndSendMessage = async ( - id: string, + s3Key: string, client: SQSClient, queueUrl: string, outputBucket: string, @@ -66,9 +66,10 @@ export const generateOutputSignedUrlAndSendMessage = async ( originalFilename: string, inputSignedUrl: string, languageCode: LanguageCode, + translate: boolean, ): Promise => { const signedUrls = await generateOutputSignedUrls( - id, + s3Key, region, outputBucket, userEmail, @@ -76,8 +77,9 @@ export const generateOutputSignedUrlAndSendMessage = async ( 7, ); + const jobId = translate ? `${s3Key}-translation` : s3Key; const job: TranscriptionJob = { - id, // id of the source file + id: jobId, // id of the source file inputSignedUrl, sentTimestamp: new Date().toISOString(), userEmail, @@ -85,8 +87,9 @@ export const generateOutputSignedUrlAndSendMessage = async ( originalFilename, outputBucketUrls: signedUrls, languageCode, + translate, }; - return await sendMessage(client, queueUrl, JSON.stringify(job), id); + return await sendMessage(client, queueUrl, JSON.stringify(job), s3Key); }; const sendMessage = async ( diff --git a/packages/client/src/components/UploadForm.tsx b/packages/client/src/components/UploadForm.tsx index c634c41c..89c4f429 100644 --- a/packages/client/src/components/UploadForm.tsx +++ b/packages/client/src/components/UploadForm.tsx @@ -9,7 +9,7 @@ import { TranscribeFileRequestBody, } from '@guardian/transcription-service-common'; import { AuthContext } from '@/app/template'; -import { FileInput, Label, Select } from 'flowbite-react'; +import { Checkbox, FileInput, Label, Select } from 'flowbite-react'; import { RequestStatus } from '@/types'; import { iconForStatus, InfoMessage } from '@/components/InfoMessage'; @@ -17,6 +17,7 @@ const uploadFileAndTranscribe = async ( file: File, token: string, languageCode: LanguageCode, + translationRequested: boolean, ) => { const blob = new Blob([file as BlobPart]); @@ -42,6 +43,7 @@ const uploadFileAndTranscribe = async ( s3Key: body.data.s3Key, fileName: file.name, languageCode, + translationRequested, }; const sendMessageResponse = await authFetch('/api/transcribe-file', token, { @@ -83,6 +85,8 @@ export const UploadForm = () => { const [languageCodeValid, setLanguageCodeValid] = useState< boolean | undefined >(undefined); + const [translationRequested, setTranslationRequested] = + useState(false); const { token } = useContext(AuthContext); const reset = () => { @@ -143,10 +147,18 @@ export const UploadForm = () => { role="alert" > Upload complete. {' '} - Transcription in progress - check your email for the completed - transcript. The service can take a few minutes to start up, but - thereafter the transcription process is typically shorter than the - length of the media file.{' '} +

+ Transcription in progress - check your email for the completed + transcript. The service can take a few minutes to start up, but + thereafter the transcription process is typically shorter than + the length of the media file.{' '} +

+

+ If you have requested a translation, you will receive 2 emails - + one for the transcription in the original language, another for + the english translation. The emails will arrive at different + times +