Skip to content

Commit 0b7aac2

Browse files
committed
added workflow for both translation and generation
Signed-off-by: Keenan Kalra <[email protected]>
1 parent 19e1afe commit 0b7aac2

File tree

10 files changed

+1104
-699
lines changed

10 files changed

+1104
-699
lines changed

oci-subtitle-translation/README.md

Lines changed: 174 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,18 @@ The solution combines two powerful OCI services:
1010

1111
This automated approach significantly reduces the time and effort required to create multilingual subtitles, making content more accessible to a global audience.
1212

13-
PUT IMAGE HERE
14-
join oracle profile
13+
## Features
14+
15+
- **Flexible Input Sources**: Accept both local audio files (MP3, WAV, etc.) and files already stored in OCI Object Storage
16+
- **Multiple Output Options**: Store generated SRT files locally, in Object Storage, or both
17+
- **Complete Workflow**: Single command to transcribe audio and translate to multiple languages
18+
- **Standalone Scripts**: Individual scripts for transcription-only or translation-only workflows
19+
- **Translation Methods**:
20+
- Synchronous translation for smaller files (subtitle-by-subtitle)
21+
- Batch translation for larger files (up to 20MB)
22+
- **Language Support**: 30+ supported languages for translation
23+
- **Configurable**: Comprehensive YAML configuration with sensible defaults
24+
1525
## 0. Prerequisites and setup
1626

1727
### Prerequisites
@@ -57,39 +67,115 @@ join oracle profile
5767
pip install -r requirements.txt
5868
```
5969

60-
3. Update `config.yaml` with your settings:
61-
```yaml
62-
# Speech Service Configuration
63-
speech:
64-
compartment_id: "ocid1.compartment.oc1..your-compartment-id"
65-
bucket_name: "your-bucket-name"
66-
namespace: "your-namespace"
67-
68-
# Language Translation Configuration
69-
language:
70-
compartment_id: "ocid1.compartment.oc1..your-compartment-id"
70+
3. Copy the example configuration and update with your settings:
71+
```bash
72+
cp config_example.yaml config.yaml
73+
# Edit config.yaml with your OCI details
7174
```
7275

7376
## 2. Usage
7477

75-
> Before running the script, make sure your input `.mp3` file has already been uploaded to the OCI Object Storage **input bucket** defined in your `config.yaml`.
76-
> The script does **not** accept local files it looks for the file in the cloud bucket only.
78+
The solution provides three main ways to use it:
7779

78-
This solution works in two steps:
80+
### Option 1: Complete Workflow (Recommended)
7981

80-
1. First, we generate SRT from audio:
82+
Use the main workflow script to transcribe audio and translate in one command:
8183

82-
```bash
83-
python generate_srt_from_audio.py --input-file your_audio.mp3
84-
```
84+
```bash
85+
# Transcribe local audio file and translate to multiple languages
86+
python workflow.py --audio-source audio.mp3 --target-languages es fr de
8587

86-
2. Then, we translate the generated SRT file to multiple languages:
88+
# Use audio file already in Object Storage
89+
python workflow.py --audio-source "audio/myfile.mp3" --target-languages es fr de pt
8790

88-
```bash
89-
python translate_srt.py --input-file input.srt
90-
```
91+
# Transcribe only (no translation)
92+
python workflow.py --transcribe-only --audio-source audio.mp3
93+
94+
# Translate only (use existing SRT file)
95+
python workflow.py --translate-only --srt-file subtitles.srt --target-languages es fr
96+
```
97+
98+
### Option 2: Individual Scripts
99+
100+
Use individual scripts for specific tasks:
101+
102+
#### Transcription Only
103+
104+
```bash
105+
# Transcribe local audio file
106+
python generate_srt_from_audio.py --input-file audio.mp3
107+
108+
# Transcribe with specific language
109+
python generate_srt_from_audio.py --input-file audio.mp3 --language es-ES
110+
111+
# Output to local only
112+
python generate_srt_from_audio.py --input-file audio.mp3 --output-type local
113+
```
114+
115+
#### Translation Only
116+
117+
```bash
118+
# Translate local SRT file to multiple languages
119+
python translate_srt.py --input-file subtitles.srt --target-languages es fr de
120+
121+
# Use synchronous translation method
122+
python translate_srt.py --input-file subtitles.srt --target-languages es --method sync
123+
124+
# Translate SRT file in Object Storage
125+
python translate_srt.py --input-file "srt_files/subtitles.srt" --target-languages es fr
126+
```
127+
128+
## 3. Configuration
129+
130+
The `config.yaml` file controls all aspects of the workflow. Key sections include:
131+
132+
### Speech Configuration
133+
```yaml
134+
speech:
135+
compartment_id: "ocid1.compartment.oc1..your-compartment-id"
136+
bucket_name: "your-speech-bucket-name"
137+
namespace: "your-namespace"
138+
language_code: "en-US" # Default transcription language
139+
```
140+
141+
### Output Configuration
142+
```yaml
143+
output:
144+
storage_type: "both" # "local", "object_storage", or "both"
145+
local_directory: "./output"
146+
object_storage_prefix: "translations"
147+
```
148+
149+
### Translation Configuration
150+
```yaml
151+
translation:
152+
target_languages:
153+
- "es" # Spanish
154+
- "fr" # French
155+
- "de" # German
156+
method: "batch" # "batch" or "sync"
157+
```
158+
159+
## 4. Supported Languages
160+
161+
### Speech-to-Text (Transcription)
162+
163+
The following language codes are supported for audio transcription:
164+
165+
| Language | Code |
166+
|----------|------|
167+
| US English | en-US |
168+
| British English | en-GB |
169+
| Australian English | en-AU |
170+
| Indian English | en-IN |
171+
| Spanish (Spain) | es-ES |
172+
| Brazilian Portuguese | pt-BR |
173+
| Hindi (India) | hi-IN |
174+
| French (France) | fr-FR |
175+
| German (Germany) | de-DE |
176+
| Italian (Italy) | it-IT |
91177
92-
## Annex: Supported Languages
178+
### Translation
93179
94180
The solution supports translation to the following languages:
95181
@@ -129,6 +215,69 @@ The solution supports translation to the following languages:
129215
130216
For an updated list of supported languages, refer to [the OCI Documentation](https://docs.oracle.com/en-us/iaas/language/using/translate.htm#supported-langs).
131217
218+
## 5. Advanced Usage
219+
220+
### Custom Configuration Files
221+
222+
```bash
223+
# Use a different configuration file
224+
python workflow.py --config my-config.yaml --audio-source audio.mp3
225+
```
226+
227+
### Working with Object Storage
228+
229+
```bash
230+
# Use files already in Object Storage (no local upload needed)
231+
python workflow.py --audio-source "audio/recording.mp3" --target-languages es fr
232+
233+
# Store output only in Object Storage
234+
python generate_srt_from_audio.py --input-file audio.mp3 --output-type object_storage
235+
```
236+
237+
### Translation Methods
238+
239+
**Batch Translation** (default):
240+
- Best for larger files (up to 20MB)
241+
- More efficient for multiple languages
242+
- Uses OCI Language batch processing
243+
244+
**Synchronous Translation**:
245+
- Best for smaller files or individual subtitles
246+
- Processes subtitle by subtitle
247+
- More reliable for very small files
248+
249+
```bash
250+
# Force synchronous translation
251+
python translate_srt.py --input-file subtitles.srt --target-languages es --method sync
252+
```
253+
254+
### Troubleshooting
255+
256+
1. **Authentication Issues**: Ensure your OCI CLI is properly configured
257+
```bash
258+
oci iam user get --user-id $(oci iam user list --query 'data[0].id' --raw-output)
259+
```
260+
261+
2. **File Size Limits**:
262+
- Audio files: No specific limit for OCI Speech
263+
- SRT files for batch translation: 20MB maximum
264+
- Large files automatically fall back to synchronous translation
265+
266+
3. **Output Directory**: The solution automatically creates output directories as needed
267+
268+
## 6. Architecture
269+
270+
The solution consists of modular components:
271+
272+
- **workflow.py**: Main orchestration script
273+
- **generate_srt_from_audio.py**: OCI Speech service integration
274+
- **translate_srt.py**: OCI Language service integration
275+
276+
This modular design allows you to:
277+
- Use individual components as needed
278+
- Integrate with existing workflows
279+
- Customize functionality for specific requirements
280+
132281
## Supported Language Codes
133282

134283
For the Speech-to-Text transcription service with GENERIC domain, the following language codes are supported:
Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
1-
# Speech Service Configuration
2-
profile: "your-profile"
1+
# OCI Subtitle Translation Configuration
2+
# Copy this file and update with your specific settings
3+
4+
# OCI Profile Configuration
5+
profile: "DEFAULT" # OCI CLI profile name
36

7+
# Speech Service Configuration
48
speech:
59
compartment_id: "ocid1.compartment.oc1..your-compartment-id"
6-
bucket_name: "your-bucket-name"
10+
bucket_name: "your-speech-bucket-name"
711
namespace: "your-namespace"
12+
language_code: "en-US" # Default language for transcription
13+
# Supported: en-US, en-GB, en-AU, en-IN, es-ES, pt-BR, hi-IN, fr-FR, de-DE, it-IT
814

915
# Language Translation Configuration
1016
language:
11-
compartment_id: "ocid1.compartment.oc1..your-compartment-id"
17+
compartment_id: "ocid1.compartment.oc1..your-compartment-id"
18+
# Optional: separate bucket for translations (if not specified, uses speech bucket)
19+
bucket_name: "" # Leave empty to use speech bucket
20+
namespace: "" # Leave empty to use speech namespace
21+
22+
# Output Configuration
23+
output:
24+
# Where to store output files: "local", "object_storage", or "both"
25+
storage_type: "both"
26+
# Local directory for output files (used when storage_type is "local" or "both")
27+
local_directory: "./output"
28+
# Object storage prefix for output files
29+
object_storage_prefix: "translations"
30+
31+
# Translation Settings
32+
translation:
33+
# Default target languages (can be overridden via command line)
34+
target_languages:
35+
- "es" # Spanish
36+
- "fr" # French
37+
- "de" # German
38+
- "pt" # Portuguese
39+
# Translation method: "batch" (for large files) or "sync" (for small files < 1000 chars per subtitle)
40+
method: "batch"

oci-subtitle-translation/download_srt.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)