https://github.com/connor-makowski/srt_file_translator

A simple python interface to translate srt files

https://github.com/connor-makowski/srt_file_translator

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 4 committers (25.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.5%) to scientific vocabulary

Keywords from Contributors

archival projection profiles interactive transformers sequences generic autograding hacking shellcodes
Last synced: 11 months ago · JSON representation

Repository

A simple python interface to translate srt files

Basic Info
  • Host: GitHub
  • Owner: connor-makowski
  • License: mit
  • Language: Python
  • Default Branch: main
  • Size: 232 KB
Statistics
  • Stars: 46
  • Watchers: 2
  • Forks: 7
  • Open Issues: 2
  • Releases: 4
Created over 7 years ago · Last pushed over 1 year ago
Metadata Files
Readme License

README.md

SRT File translator

PyPI version License: MIT

An SRT translator for Python using Google Translate. This package breaks down given SRT formatted text into individual statments that are translated individually. Multi statement lines are broken down into single statement lines and statements that span multiple lines are aggregated into a single line. This allows google translate to translate each statement as a single unit and allows reasonable similarities to the original timing of the SRT file.

Setup

Make sure you have Python 3.10.x (or higher) installed on your system. You can download it here.

Installation

pip install srt_file_translator

Getting Started

srt_file_translator contains a basic Translator wrapper class that allows for easy translations of srt files. Technical Docs Here.

You need a Google Cloud API Key to use this library. You can create a new json key here. Additonal information on how to get started using google cloud translate can be found here.

Usage

Translator Usage:

```py

Import the Translator class

from srtfiletranslator import Translator

Initialize a translator object

translator = Translator(keypath="bqkey.json")

Translate an srt file

translator.srtfiletranslator( # The path to the srt file you want to translate sourcefile="test/myscript-en.srt", # The path to the output file targetfile="test/myscript-es.srt", # The source language of the srt file sourcelanguage="en", # The target language of the output srt file targetlanguage="es" # Optionally: Specify end of statement delimiter characters # for aggregating multi line statements into a single line statement_delimiters=['.', '?', '!'] # Defaults to ['.', '?', '!'] ) ```

Show Available Languages:

py from srt_file_translator import Translator translator = Translator(key_path="bq_key.json") translator.show_languages()

Actual Example:

Consider the following srt file:

```srt 0 00:00:00,000 --> 00:00:00,500

1 00:00:00,500 --> 00:00:04,620 Welcome to an introduction on how to use

2 00:00:04,620 --> 00:00:06,600 the Translate SRT package.

3 00:00:06,600 --> 00:00:08,540 This is only an example SRT

4 00:00:08,540 --> 00:00:12,130 file for the purpose of this demonstration.

```

Using the following code:

py from srt_file_translator import Translator translator = Translator(key_path="bq_key.json") translator.srt_file_translator( source_file="example_data/welcome_example-en.srt", target_file="example_data/welcome_example-es.srt", source_language="en", target_language="es" )

Produces:

```srt 0 00:00:00,500 --> 00:00:06,600 Bienvenido a una introducción sobre cómo utilizar el paquete Translate SRT.

1 00:00:06,600 --> 00:00:12,130 Este es sólo un ejemplo de SRT. ```

Notice how the statements are aggregated into a single line before being translated. This allows google translate to translate the entire statement as a single unit. This is important because google translate will often translate individual words incorrectly if they are not in the context of an entire statement.

Additional Examples:

Translating all files in a folder to multiple languages:

```py

Import the Translator class

from srtfiletranslator import Translator

Import os for file system operations

import os

Initialize a translator object

translator = Translator(keypath="bqkey.json")

Specify the input and output folders

inputfolder = "exampledata" outputfolder = "exampleoutput"

Create the output folder if it doesn't exist

if not os.path.exists(outputfolder): os.makedirs(outputfolder)

Specify the source language and target languages

sourcelanguage = "en" targetlanguates = ["es", "fr", "de", "it", "pt", "ru", "zh", "ja", "ko"]

Loop through all files in the input folder

for file in os.listdir(inputfolder): # Loop through all target languages for targetlanguage in targetlanguates: # Translate each input file to each target language translator.srtfiletranslator( sourcefile=os.path.join(inputfolder, file), targetfile=os.path.join(outputfolder, f"{os.path.splitext(file)[0]}-{targetlanguage}.srt"), sourcelanguage=sourcelanguage, targetlanguage=targetlanguage ) ```

License

Copyright 2024 Connor Makowski

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Owner

  • Name: Connor Makowski
  • Login: connor-makowski
  • Kind: user
  • Location: Cambridge, MA

Cave Lab Project Manager and Digital Learning Lead at MIT

GitHub Events

Total
  • Create event: 1
  • Issues event: 2
  • Release event: 1
  • Watch event: 10
  • Issue comment event: 1
  • Push event: 1
Last Year
  • Create event: 1
  • Issues event: 2
  • Release event: 1
  • Watch event: 10
  • Issue comment event: 1
  • Push event: 1

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 24
  • Total Committers: 4
  • Avg Commits per committer: 6.0
  • Development Distribution Score (DDS): 0.333
Past Year
  • Commits: 7
  • Committers: 2
  • Avg Commits per committer: 3.5
  • Development Distribution Score (DDS): 0.286
Top Committers
Name Email Commits
Connor Makowski c****8@g****m 16
Connor Makowski c****k@m****u 5
Doug Williams d****i@g****m 2
dependabot[bot] 4****] 1
Committer Domains (Top 20 + Academic)
mit.edu: 1

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 5
  • Total pull requests: 11
  • Average time to close issues: 11 months
  • Average time to close pull requests: 9 months
  • Total issue authors: 5
  • Total pull request authors: 3
  • Average comments per issue: 1.2
  • Average comments per pull request: 0.82
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 7
Past Year
  • Issues: 2
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 2
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • ycadin (1)
  • vaccarieli (1)
  • wodecki (1)
  • gaiar (1)
  • srghma (1)
Pull Request Authors
  • dependabot[bot] (7)
  • connor-makowski (5)
  • williamsdoug (2)
Top Labels
Issue Labels
Pull Request Labels
dependencies (7)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 73 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 4
  • Total maintainers: 1
pypi.org: srt-file-translator

A python translator for srt files.

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 73 Last month
Rankings
Dependent packages count: 10.1%
Average: 38.7%
Dependent repos count: 67.4%
Maintainers (1)
Last synced: 11 months ago

Dependencies

requirements.txt pypi
  • cachetools ==3.0.0
  • certifi ==2018.11.29
  • chardet ==3.0.4
  • google-api-core ==1.7.0
  • google-auth ==1.6.2
  • google-cloud-core ==0.29.1
  • google-cloud-translate ==1.3.3
  • googleapis-common-protos ==1.5.5
  • idna ==2.8
  • protobuf ==3.6.1
  • pyasn1 ==0.4.4
  • pyasn1-modules ==0.2.2
  • pytz ==2018.7
  • requests ==2.21.0
  • rsa ==4.0
  • six ==1.12.0
  • urllib3 ==1.24.2
pyproject.toml pypi
  • google-cloud-translate ==3.12.1
  • type_enforced >=1.2.0