Skip to content

Commit

Permalink
Merge pull request #41 from MarcWeberFS:7-transcribe-audio-into-text
Browse files Browse the repository at this point in the history
7-transcribe-audio-into-text
  • Loading branch information
MarcWeberFS authored Nov 12, 2024
2 parents a250b4d + 9821090 commit a612f60
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 56 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
USER: ${{ secrets.AWS_EC2_USER }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ secrets.AWS_REGION }}
INSTAGRAM_USERNAME: ${{ secrets.INSTAGRAM_USERNAME }}
INSTAGRAM_PASSWORD: ${{ secrets.INSTAGRAM_PASSWORD }}
run: |
echo "${{ secrets.AWS_EC2_PEM }}" > /tmp/key.pem
chmod 600 /tmp/key.pem
Expand All @@ -68,6 +70,13 @@ jobs:
docker rm backend frontend || true
docker pull $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-backend
docker pull $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-frontend
docker run -d --network=my-app-network --name backend -p 8080:8080 $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-backend
docker run -d --network=my-app-network --name frontend -p 80:80 $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-frontend
# Run backend and frontend with Instagram credentials passed as environment variables
docker run -d --network=my-app-network --name backend -p 8080:8080 \
-e INSTAGRAM_USERNAME="$INSTAGRAM_USERNAME" \
-e INSTAGRAM_PASSWORD="$INSTAGRAM_PASSWORD" \
$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-backend
docker run -d --network=my-app-network --name frontend -p 80:80 \
$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/video-downloader-frontend
EOF
9 changes: 9 additions & 0 deletions video-downloader-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/transcribe -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>transcribe</artifactId>
<version>2.29.9</version>
</dependency>



</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class VideoDownloadController {
public ResponseEntity<Map<String, String>> startDownloadProcess(@RequestParam("url") String url) {
Map<String, Object> variables = new HashMap<>();
variables.put("url", url);
variables.put("advanced", false);
variables.put("advanced", true);

ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process_1ua4l8j", variables);
Map<String, String> response = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public void execute(DelegateExecution execution) throws Exception {
String s3BucketName = "video-download-temp";
String s3Folder = "instagram-videos";

execution.setVariable("bucketName", s3BucketName);
execution.setVariable("folder", s3Folder);

String result = downloadInstagramVideo(url, s3BucketName, s3Folder);

System.out.println("Download result: " + result);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ch.marc.delegates;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;

import software.amazon.awssdk.services.transcribe.TranscribeClient;
import software.amazon.awssdk.services.transcribe.model.*;

@Component
public class TranscribeVideoDelegate implements JavaDelegate {

@Override
public void execute(DelegateExecution execution) {
String downloadLink = (String) execution.getVariable("downloadLink");

String s3Uri = downloadLink.replace("https://video-download-temp.s3.amazonaws.com/", "s3://video-download-temp/");

TranscribeClient transcribeClient = TranscribeClient.builder().build();

StartTranscriptionJobRequest transcriptionJobRequest = StartTranscriptionJobRequest.builder()
.transcriptionJobName("TranscriptionJob_" + System.currentTimeMillis())
.languageCode(LanguageCode.EN_US)
.mediaFormat(MediaFormat.MP4)
.media(Media.builder().mediaFileUri(s3Uri).build())
.subtitles(Subtitles.builder().formats(SubtitleFormat.SRT).build())
.build();

try {
StartTranscriptionJobResponse transcriptionJobResponse = transcribeClient.startTranscriptionJob(transcriptionJobRequest);
System.out.println("Transcription job started with ID: " + transcriptionJobResponse.transcriptionJob().transcriptionJobName());

execution.setVariable("transcriptionJobId", transcriptionJobResponse.transcriptionJob().transcriptionJobName());

} catch (TranscribeException e) {
System.err.println("Error starting transcription job: " + e.awsErrorDetails().errorMessage());
throw new RuntimeException("Transcription job failed", e);
} finally {
transcribeClient.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,31 @@
<bpmn:incoming>Flow_0y4bow3</bpmn:incoming>
<bpmn:outgoing>Flow_1wi0v5y</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1wi0v5y" sourceRef="Activity_0apq88t" targetRef="Gateway_0l2ncfn" />
<bpmn:sequenceFlow id="Flow_1wi0v5y" sourceRef="Activity_0apq88t" targetRef="Activity_1uzicf2" />
<bpmn:serviceTask id="Activity_1uzicf2" name="Generate Download Link" camunda:delegateExpression="${generateDownloadLinkDelegate}">
<bpmn:incoming>Flow_160xutx</bpmn:incoming>
<bpmn:outgoing>Flow_1kmn8mj</bpmn:outgoing>
<bpmn:incoming>Flow_1wi0v5y</bpmn:incoming>
<bpmn:outgoing>Flow_1g1t3hq</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:endEvent id="Event_0uaetw3">
<bpmn:incoming>Flow_1kmn8mj</bpmn:incoming>
<bpmn:incoming>Flow_1pf7l1x</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1kmn8mj" sourceRef="Activity_1uzicf2" targetRef="Event_0uaetw3" />
<bpmn:sequenceFlow id="Flow_0y4bow3" sourceRef="Activity_1a3s07l" targetRef="Activity_0apq88t" />
<bpmn:exclusiveGateway id="Gateway_0l2ncfn">
<bpmn:incoming>Flow_1wi0v5y</bpmn:incoming>
<bpmn:incoming>Flow_1g1t3hq</bpmn:incoming>
<bpmn:outgoing>Flow_0sarfuf</bpmn:outgoing>
<bpmn:outgoing>Flow_0k0ot69</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_0sarfuf" sourceRef="Gateway_0l2ncfn" targetRef="Gateway_1bf3qhf">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${advanced==false}</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:task id="Activity_1ombwrr" name="Transcribe Video">
<bpmn:incoming>Flow_0k0ot69</bpmn:incoming>
<bpmn:outgoing>Flow_1rdrtnn</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_0k0ot69" sourceRef="Gateway_0l2ncfn" targetRef="Activity_1ombwrr">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${advanced==true}</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:task id="Activity_1e3vfll" name="Translate Transcription">
<bpmn:incoming>Flow_1rdrtnn</bpmn:incoming>
<bpmn:incoming>Flow_1nknvr7</bpmn:incoming>
<bpmn:outgoing>Flow_0q66msg</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1rdrtnn" sourceRef="Activity_1ombwrr" targetRef="Activity_1e3vfll" />
<bpmn:sequenceFlow id="Flow_1rdrtnn" sourceRef="Activity_1ombwrr" targetRef="Activity_0878v3m" />
<bpmn:task id="Activity_0ghmzhn" name="Add Captions To Video">
<bpmn:incoming>Flow_0q66msg</bpmn:incoming>
<bpmn:outgoing>Flow_1nnbcnd</bpmn:outgoing>
Expand All @@ -56,10 +51,20 @@
<bpmn:exclusiveGateway id="Gateway_1bf3qhf">
<bpmn:incoming>Flow_0sarfuf</bpmn:incoming>
<bpmn:incoming>Flow_1nnbcnd</bpmn:incoming>
<bpmn:outgoing>Flow_160xutx</bpmn:outgoing>
<bpmn:outgoing>Flow_1pf7l1x</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_160xutx" sourceRef="Gateway_1bf3qhf" targetRef="Activity_1uzicf2" />
<bpmn:sequenceFlow id="Flow_1nnbcnd" sourceRef="Activity_0ghmzhn" targetRef="Gateway_1bf3qhf" />
<bpmn:task id="Activity_0878v3m" name="Transcription Status">
<bpmn:incoming>Flow_1rdrtnn</bpmn:incoming>
<bpmn:outgoing>Flow_1nknvr7</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1nknvr7" sourceRef="Activity_0878v3m" targetRef="Activity_1e3vfll" />
<bpmn:serviceTask id="Activity_1ombwrr" name="Transcribe Video" camunda:delegateExpression="${transcribeVideoDelegate}">
<bpmn:incoming>Flow_0k0ot69</bpmn:incoming>
<bpmn:outgoing>Flow_1rdrtnn</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_1g1t3hq" sourceRef="Activity_1uzicf2" targetRef="Gateway_0l2ncfn" />
<bpmn:sequenceFlow id="Flow_1pf7l1x" sourceRef="Gateway_1bf3qhf" targetRef="Event_0uaetw3" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1ua4l8j">
Expand All @@ -70,76 +75,83 @@
<dc:Bounds x="270" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0uaetw3_di" bpmnElement="Event_0uaetw3">
<dc:Bounds x="1542" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0apq88t_di" bpmnElement="Activity_0apq88t">
<dc:Bounds x="460" y="77" width="100" height="80" />
<dc:Bounds x="430" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_0l2ncfn_di" bpmnElement="Gateway_0l2ncfn" isMarkerVisible="true">
<dc:Bounds x="625" y="92" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1ombwrr_di" bpmnElement="Activity_1ombwrr">
<dc:Bounds x="740" y="190" width="100" height="80" />
<bpmndi:BPMNShape id="Activity_1uzicf2_di" bpmnElement="Activity_1uzicf2">
<dc:Bounds x="580" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_0l2ncfn_di" bpmnElement="Gateway_0l2ncfn" isMarkerVisible="true">
<dc:Bounds x="725" y="92" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1e3vfll_di" bpmnElement="Activity_1e3vfll">
<dc:Bounds x="920" y="190" width="100" height="80" />
<dc:Bounds x="1110" y="190" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ghmzhn_di" bpmnElement="Activity_0ghmzhn">
<dc:Bounds x="1100" y="190" width="100" height="80" />
<dc:Bounds x="1260" y="190" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0uaetw3_di" bpmnElement="Event_0uaetw3">
<dc:Bounds x="1542" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1uzicf2_di" bpmnElement="Activity_1uzicf2">
<dc:Bounds x="1380" y="77" width="100" height="80" />
<bpmndi:BPMNShape id="Activity_0878v3m_di" bpmnElement="Activity_0878v3m">
<dc:Bounds x="960" y="190" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0n8jbux_di" bpmnElement="Activity_1ombwrr">
<dc:Bounds x="810" y="190" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_1bf3qhf_di" bpmnElement="Gateway_1bf3qhf" isMarkerVisible="true">
<dc:Bounds x="1245" y="92" width="50" height="50" />
<dc:Bounds x="1385" y="92" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_17td0b4_di" bpmnElement="Flow_17td0b4">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1wi0v5y_di" bpmnElement="Flow_1wi0v5y">
<di:waypoint x="560" y="117" />
<di:waypoint x="625" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1kmn8mj_di" bpmnElement="Flow_1kmn8mj">
<di:waypoint x="1480" y="117" />
<di:waypoint x="1542" y="117" />
<di:waypoint x="530" y="117" />
<di:waypoint x="580" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0y4bow3_di" bpmnElement="Flow_0y4bow3">
<di:waypoint x="370" y="117" />
<di:waypoint x="460" y="117" />
<di:waypoint x="430" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0sarfuf_di" bpmnElement="Flow_0sarfuf">
<di:waypoint x="675" y="117" />
<di:waypoint x="1245" y="117" />
<di:waypoint x="775" y="117" />
<di:waypoint x="1385" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1nnbcnd_di" bpmnElement="Flow_1nnbcnd">
<di:waypoint x="1360" y="230" />
<di:waypoint x="1410" y="230" />
<di:waypoint x="1410" y="142" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1g1t3hq_di" bpmnElement="Flow_1g1t3hq">
<di:waypoint x="680" y="117" />
<di:waypoint x="725" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1pf7l1x_di" bpmnElement="Flow_1pf7l1x">
<di:waypoint x="1435" y="117" />
<di:waypoint x="1542" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0k0ot69_di" bpmnElement="Flow_0k0ot69">
<di:waypoint x="650" y="142" />
<di:waypoint x="650" y="230" />
<di:waypoint x="740" y="230" />
<di:waypoint x="750" y="142" />
<di:waypoint x="750" y="230" />
<di:waypoint x="810" y="230" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1rdrtnn_di" bpmnElement="Flow_1rdrtnn">
<di:waypoint x="840" y="230" />
<di:waypoint x="920" y="230" />
<bpmndi:BPMNEdge id="Flow_1nknvr7_di" bpmnElement="Flow_1nknvr7">
<di:waypoint x="1060" y="230" />
<di:waypoint x="1110" y="230" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0q66msg_di" bpmnElement="Flow_0q66msg">
<di:waypoint x="1020" y="230" />
<di:waypoint x="1100" y="230" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_160xutx_di" bpmnElement="Flow_160xutx">
<di:waypoint x="1295" y="117" />
<di:waypoint x="1380" y="117" />
<di:waypoint x="1210" y="230" />
<di:waypoint x="1260" y="230" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1nnbcnd_di" bpmnElement="Flow_1nnbcnd">
<di:waypoint x="1200" y="230" />
<di:waypoint x="1270" y="230" />
<di:waypoint x="1270" y="142" />
<bpmndi:BPMNEdge id="Flow_1rdrtnn_di" bpmnElement="Flow_1rdrtnn">
<di:waypoint x="910" y="230" />
<di:waypoint x="960" y="230" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
Expand Down

0 comments on commit a612f60

Please sign in to comment.